Skip to main content
sdk.gateway is a MolphaGateway: it signs the request, runs a round on a Molpha gateway and returns an Attestation. This page covers its methods and retry behaviour; for the HTTP API, auth digest and error codes, see gateways.
The gateway response is unverified. The SDK checks that the response matches what you asked for (sourceId, signaturesRequired, aggregation) but does not check the aggregate signature. Verify the attestation before you act on its value: submit it to Solana, or call the EVM, Starknet or Solana verifier.

Endpoints

The client posts to its endpoints in order and moves to the next one on any retryable failure (see retries and errors). The default is DEFAULT_GATEWAY_ENDPOINT, https://gateway.molpha.io/ (devnet).
The request signature binds the gateway’s on-chain account, so the client needs each gateway’s authority key. When you omit gatewayAuthority, the client reads it once per endpoint from GET /v1/info and throws if the gateway reports a different programId.

requestSignedData

For each call the SDK:
  1. Canonicalizes apiConfig and derives its sourceId (see feeds). An invalid aggregation, or tolerance mode with signaturesRequired < 3, throws AggregationConfigError before any request.
  2. Reads the current registry version, redundancy buffer and node count from Solana, unless you pass a context.
  3. Signs RequestAuth with a fresh authTimestamp for each attempt and endpoint, and posts to POST /v1/round/execute.
  4. Rejects a response whose sourceId, signaturesRequired or aggregation differs from the request, or that lacks a signed field.
The gateway assigns the round’s timestamp (unix milliseconds); you never send one. How rounds are timed and shared between callers is described in round timing. All options are listed in RequestSignedDataOptions. The ones you set most often:

Private APIs

Put secrets in the URL or headers as {{secret.<name>}} placeholders and pass their values in encrypt.secrets:
The SDK encrypts the secrets for every node of the registry version, because the committee is not known until the gateway stamps the round. Before encrypting, MolphaSDK checks the gateway’s node keys against the on-chain Node accounts (solana.verifyNodeKeysForPrivateApi). A standalone MolphaGateway throws unless you pass verifyNodeKeys or set the unsafe allowUnverifiedNodeKeysForPrivateApi. The sourceId is derived from the config with its placeholders, never from the secret values.

Paywalled API sources

When the API source itself answers HTTP 402 (x402), pass sourcePayment to pay it from your own EVM wallet:
The SDK reads the source’s 402 terms and signs one authorization per node in the round’s eligible set, min(signaturesRequired + redundancyBuffer, nodeCount). Only authorizations a node spends settle. Payment goes to the source, not to Molpha, and the round still costs one unit of subscription quota. The SDK signs exact USDC payments on Base and Base Sepolia only. Without sourcePayment, a paywalled source throws UpstreamPaymentRequiredError with the gateway’s quote. This is separate from paying Molpha per request with x402. The SDK does not wrap the x402 pay-per-request endpoint; call it over HTTP as described there.

prepareContext

Reads the registry version, redundancy buffer and node count from Solana and the node list from GET /v1/nodes, in parallel, and returns a RoundContext. With a full context, each requestSignedData is a single POST. Nothing is cached automatically. If the gateway reports that the context’s registry version is no longer current, the call re-reads the registry once and retries without spending an attempt; still refresh a long-lived context when the registry version changes.

requestAndSubmit

Calls requestSignedData with the same options, then sdk.solana.submitAttestation(result), which verifies the signature on-chain and writes the submitter’s Feed account. If the round succeeds but the submit fails, it throws SubmitFailedError. The round is already paid for, so resubmit error.result instead of requesting a new one:
To update many feeds, use requestMany.

Retries and errors

requestSignedData makes up to maxRetries attempts and throws the last error when they run out. Each attempt tries every endpoint in order. There is no idempotency key: every attempt the gateway accepts is a new round that spends another unit of quota. retryDelayMs(cause, failures) exposes the delay calculation. Error classes are listed in errors.