Skip to main content
Use @molpha/sdk to subscribe, request a signed attestation for an API, publish it to a Solana feed, and check the same attestation with an EVM verifier. The SDK’s defaults point at the current deployment: the gateway https://gateway.molpha.io and the Molpha program on Solana devnet. You need a Solana devnet wallet with a little Devnet SOL and Devnet USDC:
Get Devnet USDC from the Circle faucet (choose USDC on Solana Devnet). The Basic plan costs 20 USDC on the current deployment; step 3 prints the price before paying it. The SDK is ESM-only. Put the code below in one file, quickstart.ts, in a project whose package.json has "type": "module", and run it with npx tsx quickstart.ts.
1

Install

Requires Node.js 20.19 or later. @anchor-lang/core and bn.js are peer dependencies of the Solana client; viem is only for the last step.
2

Initialize

walletFromKeypairFile takes a path and does not expand ~. The wallet signs Solana transactions and the gateway’s per-request authorization.
3

Subscribe

Gateway rounds from the SDK are paid by a subscription. Subscribe once with the signing wallet:
subscribe transfers the plan price in Devnet USDC from your wallet and cannot be undone. It fails if the wallet already has a subscription, which is why the call is guarded.
maxPriceUsdc aborts the transaction if the on-chain price is higher than you approved. Without a subscription (or delegate access) the gateway answers 403. To pay per round instead, see Pay per round.
4

Define a source

A source is one JSON document; jsonPriceSource builds the common case of one JSON number from one URL, and its sourceId is the hash of the document. This example never changes, so every node reads the same value. Replace it with your own API afterwards: pick an endpoint that returns the same value to every node, or use tolerance mode for live-moving numbers. Source format covers several inputs, chain reads, assertions and other output types. signaturesRequired must be at least 3, the network minimum.
5

Request a signed attestation

result is an Attestation. Treat it as unverified until a verifier has checked it. The call spends one round of your subscription’s quota. It retries on its own: a 409 (a second request for this source and quorum in the same 100 ms tick) after one tick, a 503 or 429 after the gateway’s Retry-After. Each retry is a new round.
6

Publish it to Solana

The program verifies the attestation before writing. The first submit creates the Feed account for (sourceId, signaturesRequired, your wallet); account.value holds the 32 signed bytes.
7

Verify it on an EVM chain

The same attestation verifies on EVM and Starknet. Call the deployed verifier on Base Sepolia:
MOLPHA_VERIFIER_ADDRESS is 0xae75409cb23EB85023d23A7AE37B322e53B9d485 on Sepolia, Arbitrum Sepolia, Base Sepolia, Avalanche Fuji and BNB Smart Chain testnet. For Starknet, use buildStarknetVerifierArgs and parseStarknetVerifyResult. A contract does the same check on-chain: see the smart contract quickstart.

Pay per round instead

Without a subscription, pay for each round in USDC over x402: 0.10 USDC for a round at quorum 3 on the current deployment. The SDK 0.3.0 has no x402 round client. Use one of these:
  • The MCP server: execute_x402_round on the local server signs the payment with its own wallet and, with autoSubmit: true, publishes the attestation to Solana in the same call. The hosted server returns the payment for your wallet to sign.
  • The gateway’s HTTP API: GET /v1/x402/status for the price and POST /v1/x402/execute for the round. The response has the same shape as a subscription round’s.

Next steps

Maintain a feed

Keep a Solana feed current, batch submits and request many sources.

Source format

Several inputs, chain reads, assertions and tolerance mode.

SDK reference

Every client, type and helper.