Go from zero to a verified on-chain data feed with the Molpha SDK in under five minutes.
The Molpha SDK lets you turn off-chain API responses into threshold-signed, verified on-chain data. This guide walks you through the full consumer flow on Solana Devnet: subscribe to a plan, create an oracle job, run a gateway round, and submit the signed result on-chain.
The package is ESM with "sideEffects": false. Gateway-only or read-only apps that skip the Solana imports can tree-shake the Anchor-heavy path entirely.
2
Initialize the SDK
MolphaSDK wires the gateway client and the Solana client together behind a single wallet.
import { Connection } from "@solana/web3.js";import { MolphaSDK } from "@molpha-oracle/sdk";import { walletFromKeypairFile } from "@molpha-oracle/sdk/utils";const sdk = new MolphaSDK({ connection: new Connection("https://api.devnet.solana.com", "confirmed"), wallet: walletFromKeypairFile("~/.config/solana/id.json"),});
walletFromKeypairFile is Node.js-only. In the browser, pass a MolphaWallet backed by a wallet adapter instead:
import type { MolphaWallet } from "@molpha-oracle/sdk";const wallet: MolphaWallet = { publicKey: adapter.publicKey, signTransaction: (tx) => adapter.signTransaction(tx), signAllTransactions: (txs) => adapter.signAllTransactions(txs), signAuthMessage: async (msg) => new Uint8Array(await adapter.signMessage(msg)),};
3
Subscribe to a plan
Subscriptions are paid in USDC on Solana. Fetch the live plan price first and pass it as a safety bound — the transaction aborts if the on-chain price is higher than what the user approved.
import { PlanType } from "@molpha-oracle/sdk";const plan = await sdk.solana.getPlan(PlanType.Basic);const { pricePaid } = await sdk.solana.subscribe(PlanType.Basic, { maxPriceUsdc: plan.subscriptionPrice,});
4
Create a job
A job commits to a specific off-chain data source and parsing logic. Only the hash of the API config is stored on-chain — large payloads and secrets stay off-chain.
requestAndSubmit runs a gateway round against the current on-chain registry version, receives a threshold-signed data update, and submits it to Solana — all in one call.
The returned DataUpdateResult includes the signed value, canonical timestamp, registry version, required quorum, signer bitmap, and aggregate signature.
6
Read the feed
Read the finalized on-chain feed value at any time:
import { Connection } from "@solana/web3.js";import { MolphaSDK, PlanType, deriveApiConfigHash } from "@molpha-oracle/sdk";import { walletFromKeypairFile } from "@molpha-oracle/sdk/utils";const sdk = new MolphaSDK({ connection: new Connection("https://api.devnet.solana.com", "confirmed"), wallet: walletFromKeypairFile("~/.config/solana/id.json"),});// 1. Subscribe (USDC on Solana Devnet)const plan = await sdk.solana.getPlan(PlanType.Basic);await sdk.solana.subscribe(PlanType.Basic, { maxPriceUsdc: plan.subscriptionPrice,});// 2. Create a job committed to an API config hashconst apiConfig = { url: "https://api.example.com/price", responseParser: "$.price",};const { jobId } = await sdk.solana.createJob({ apiConfigHash: deriveApiConfigHash(apiConfig), signaturesRequired: 3, decimals: 8,});// 3. Run a gateway round and submit the signed result on-chainconst { signature } = await sdk.requestAndSubmit(jobId, { apiConfig });console.log("Submitted:", signature);// 4. Read the verified feedconst feed = await sdk.solana.readFeed(jobId);console.log("Latest value:", feed.value);
Without a signAuthMessage-capable wallet (or a keypair-backed wallet), gateway execution falls back to an all-zero authSig. That path is for development only — production jobs should authenticate gateway execution.