Introduction
Molpha is a decentralized oracle network that provides reliable and secure data feeds for various assets. This guide will walk you through the process of integrating with Molpha oracles on the Solana blockchain, allowing your programs to access real-time data.Key Concepts
The Molpha oracle program is built around a few key accounts:The Feed Account
The Feed account is the primary account you will interact with. It stores all the information about a specific data feed, including:
name_hash: A unique identifier for the feed.authority: The public key of the account that can manage the feed.latest_answer: The most recent data point published to the feed.answer_history: A circular buffer containing the history of recent answers.subscription_due_time: The timestamp when the feed subscription expires.
Feed account is defined as follows:
The Answer Struct
The Answer struct contains the actual data value and the timestamp when it was recorded.
value is a 32-byte array, which can represent different data types depending on the feed. For example, for a price feed, it could be a scaled integer.
On-chain Integration
To use Molpha oracle data in your Solana program, you need to:- Pass the
Feedaccount to your instruction. - Deserialize the account data.
- Access the
latest_answerto get the current value.
1. Define the Instruction Context
First, define the accounts required for your instruction. You’ll need theFeed account from the Molpha oracle program.
2. Implement the Instruction Logic
In your instruction logic, you can access the deserializedmolpha_feed account and read its latest_answer.
3. Full Example
Here is a complete example of a Solana program that reads from a Molpha oracle.Off-chain Usage with TypeScript
You can also fetch and use Molpha oracle data from off-chain applications using TypeScript.Next Steps
- Smart Contracts Guide — Learn about contract architecture
- API Reference — Complete SDK documentation
- EVM Integration — Integrate on EVM chains