> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molpha.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Molpha Data

> Ready-made Molpha sources for on-chain and public reference data, served by the gateway: pick a template, pass its parameters, get a threshold-signed value.

Molpha Data is a catalog of **templates** served by the gateway under `/v1/data`. A template turns a few parameters
(a chain, a token, a pool, a wallet, a date) into a complete Molpha [source](https://docs.molpha.io/concepts/feeds.md), so a common value
needs no hand-written source. Each template has its own route. A `GET` on it runs a round on the template's source
and returns the threshold-signed value, paid with x402 or with your subscription.

> [!NOTE]
>
> This release runs on Solana devnet. The nodes that sign Molpha Data values read the chains listed by
> `GET /v1/data/chains`, mainnets included (Ethereum, Base, Arbitrum, Solana, Starknet and others). A value read from a
> mainnet is signed by the devnet node set: say so wherever you show it.

## How a template becomes a signed value

1. **Template and parameters.** For example `token.supply` with `chain=ethereum` and `token=0xa0b8…eb48` (USDC).
2. **Source.** The gateway expands them into a source document. Facts the template needs from chain, such as a
   token's decimals or a pool's tokens, are read once by two nodes that must agree, and written into the source as
   constants. The gateway itself reads no chain and fetches no URL.
3. **Source ID.** `sourceId` is the keccak256 of the source's canonical bytes, as for any source. The same template,
   version and parameters give the same source, so the same feed, as long as the facts on chain do not change.
4. **Round.** The source goes to the gateway's execute route, `POST /v1/x402/execute` or `POST /v1/round/execute`,
   exactly as if you had posted it yourself. The answer is the execute route's own: a signed attestation you
   [verify](https://docs.molpha.io/verifiers/overview.md) like any other.

A change to what a template builds ships as a new template version (`token.supply@1`, `dex.pool.price@2`), so the
sources of a version stay the same.

## Routes

Base URL: `https://gateway.molpha.io`. `GET /v1/info` reports `data: true` when a gateway serves Molpha Data.

| Route | What it does | Cost |
| - | - | - |
| `GET /v1/data/chains` | The chains templates may read here, and what the `final` and `fast` finality profiles resolve to | Free |
| `GET /v1/data/catalog` | Every template: parameters, return type, caveats, notices, chains. Filters: `chain`, `class` | Free |
| `GET /v1/data/catalog/{templateId}` | One template, with or without its version (`token.supply` or `token.supply@1`) | Free |
| `GET /v1/data/<template>` | The signed value. The template ID with each dot a slash: `token.supply` is `/v1/data/token/supply` | One round |
| `GET /v1/data/<template>/source` | The source the parameters build and its `sourceId`. Nothing is signed | Free, rate-limited |
| `GET /v1/data/<template>/dry-run` | The source run once on one node, unsigned. Status only, never the value | Free, rate-limited |
| `POST /v1/data/derive` | `{template, params}` or `{source}` in the body: the same answer as `/source` | Free, rate-limited |
| `POST /v1/data/dry-run` | The same answer as `<template>/dry-run`, for a template or a raw source | Free, rate-limited |
| `GET /v1/data/openapi.json` | An OpenAPI 3.1 document with one operation per template route, generated from this gateway's catalog | Free |

A template's parameters are query parameters of the same names. The value route also takes `signaturesRequired`
(default 3). The [API reference](https://docs.molpha.io/data/api/list-templates.md) has every route with its parameters.

## Try it

```bash theme={null}
# What can I read?
curl "https://gateway.molpha.io/v1/data/catalog?class=token"

# Which source does this build, and what is its ID? (free)
curl "https://gateway.molpha.io/v1/data/token/supply/source?chain=ethereum&token=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

# Does it run on a node now? (free; status only)
curl "https://gateway.molpha.io/v1/data/token/supply/dry-run?chain=ethereum&token=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

# The signed value. Without a session the answer is 402 with the x402 quote.
curl -i "https://gateway.molpha.io/v1/data/token/supply?chain=ethereum&token=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
```

[Signed reads](https://docs.molpha.io/data/signed-reads.md) covers paying for the round, the response and verification.

## The `/source` answer

`/source` and `POST /v1/data/derive` return:

| Field | Meaning |
| - | - |
| `sourceId` | keccak256 of `canonical`: the feed's identity, the value every verifier checks against |
| `source` | The source document |
| `canonical` | Its canonical JSON text (sorted keys, no whitespace, every number a string) |
| `mode` | `exact` or `tolerance` (the source has an `aggregation` block) |
| `template`, `params`, `chain` | The template with its version, the normalized parameters (defaults filled in, the chain as a CAIP-2 ID) |
| `facts` | What was read from chain to build the source, such as `decimals` |
| `layout` | For a snapshot template: the fields of the signed preimage (name, offset, length, type) |

Re-hash `canonical` (or parse `source` with the SDK's `parseSource` and compare `idHex`) before you trust
`sourceId`. `<template>/dry-run` adds `dryRun`: `status` (`ok` or `failed`), and per input whether it was read, the
block it was pinned to, the upstream's HTTP status on a refusal, the decoded fields' names and types, and on a
failure the `stage` and `input` it stopped at.

## Chains and finality

Every chain template takes `chain` (an alias such as `ethereum`, or a CAIP-2 ID such as `eip155:1`) and
`finality`: `final` (the default), `fast`, or a raw mode (`finalized`, `safe` and `confirmations:<n>` on EVM and
Starknet, `confirmed` on Solana). Finality is part of the source, so `final` and `fast` reads of the same value are
two feeds. On this gateway the profiles resolve to:

| Chain | Alias | `final` | `fast` |
| - | - | - | - |
| Ethereum `eip155:1` | `ethereum` | finalized, about 20 minutes behind | 3 confirmations |
| Ethereum Sepolia `eip155:11155111` | `sepolia` | finalized, about 20 minutes behind | 3 confirmations |
| Arbitrum One `eip155:42161` | `arbitrum` | 60 confirmations | 36 confirmations |
| Base `eip155:8453` | `base` | 60 confirmations | 18 confirmations |
| Base Sepolia `eip155:84532` | `base-sepolia` | 60 confirmations | 18 confirmations |
| BNB Smart Chain `eip155:56` | `bnb` | finalized | finalized |
| HyperEVM `eip155:999` | `hyperevm` | 60 confirmations | 36 confirmations |
| Polygon PoS `eip155:137` | | finalized | finalized |
| Monad `eip155:143` | | finalized | finalized |
| Solana `solana:5eykt4Us…` | `solana` | `finalized` commitment | `confirmed` commitment |
| Solana devnet `solana:EtWTRABZ…` | `solana-devnet` | `finalized` commitment | `confirmed` commitment |
| Starknet `starknet:SN_MAIN` | `starknet` | 100 confirmations | 6 confirmations |
| Starknet Sepolia `starknet:SN_SEPOLIA` | `starknet-sepolia` | 100 confirmations | 6 confirmations |

`GET /v1/data/chains` is the authority: it lists the chains this gateway serves and the exact lag of each profile.
Templates over a web API (reference rates, Hyperliquid) take no `chain` or `finality`.

## Limits

* `/source`, `/dry-run`, `POST /v1/data/derive` and `POST /v1/data/dry-run` are limited per client address (`429`
  with `Retry-After`) and in total (`503` with `Retry-After`). A derived source is kept for 10 minutes per template
  and parameters, so repeating a request in that window does not read the facts again and, on the value route, does
  not count against the per-address limit.
* The value route is a round: the gateway's own admission and per-consumer limits apply (`429`, `503`), and one
  consumer gets one round per feed per 100 ms tick (`409`). See [Signed reads](https://docs.molpha.io/data/signed-reads.md).
* Discovery routes (`chains`, `catalog`, `openapi.json`) are cacheable for 60 seconds.

## Errors

Failures before a round use the Molpha Data error body:

```json theme={null}
{ "error": { "code": "PARAM_INVALID", "message": "token.supply: chain: unknown chain \"nochain\"" } }
```

`stage` and `input` are added when a fact read or a dry-run stopped at a known point.

| HTTP | `code` | When |
| - | - | - |
| 400 | `BAD_REQUEST` | Malformed body, or a query parameter given more than once |
| 400 | `PARAM_INVALID` | `signaturesRequired` is not a whole number from 1 to 255 |
| 404 | `NOT_FOUND` | Unknown template |
| 422 | `PARAM_INVALID` | A parameter is wrong, the template does not run on that chain, or the chain shows the parameter names something else (a token that is not a reserve, a pool of another kind) |
| 422 | `SOURCE_INVALID` | A node refused the source |
| 429 | `RATE_LIMITED` | Too many requests from this address; retry after `Retry-After` |
| 503 | `RPC_UNAVAILABLE`, `NODES_DISAGREE`, `UNAVAILABLE` | No node could read a fact, the nodes read different facts, or no node could run the source now; retry after `Retry-After` |

Once the round starts, errors are the execute routes' own `{status, error}` body.

## Agents

For AI agents, the MCP server's data tools are described in [MCP tools](https://docs.molpha.io/mcp/tools.md).

## Not offered

* No unsigned value: a dry-run reports whether a source runs and what it read, never the value. A value comes from a
  signed round.
* No USD conversion: a DEX price names its quote token.
* Each template lists what it cannot do in its `caveats`, and the terms of its publisher in `notices`. Carry the
  notices when you show or pass a value on.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.