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.
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 isDEFAULT_GATEWAY_ENDPOINT, https://gateway.molpha.io/ (devnet).
gatewayAuthority, the client reads it once per endpoint from GET /v1/info and throws if the gateway reports a different programId.
requestSignedData
- Canonicalizes
apiConfigand derives itssourceId(see feeds). An invalidaggregation, or tolerance mode withsignaturesRequired < 3, throwsAggregationConfigErrorbefore any request. - Reads the current registry version, redundancy buffer and node count from Solana, unless you pass a
context. - Signs
RequestAuthwith a freshauthTimestampfor each attempt and endpoint, and posts toPOST /v1/round/execute. - Rejects a response whose
sourceId,signaturesRequiredoraggregationdiffers from the request, or that lacks a signed field.
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:
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), passsourcePayment to pay it from your own EVM wallet:
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
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
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:
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.