Read the chain from your app
A complete Gateway call, from fetch to live balance, with what it cost.
Your deployed app can read the chain with one fetch call: no RPC account, no key management, no SDK. This guide reads a wallet's ETH balance on Base through the Gateway and shows you what the call cost, end to end.
What you already have
Every deploy through Modus injects two env vars into your app: MODUS_GATEWAY_URL and MODUS_GATEWAY_KEY. You don't create them, and there's nothing to paste.
If you're building in the Code chapter, the agent knows the Gateway too; "show the creator's ETH balance on the dashboard" gets you this wiring without writing it yourself. This guide is for when you want to understand or hand-write the call.
The call
RPC providers take the network as a path segment. Reading a balance on Base through Alchemy:
const res = await fetch(
process.env.MODUS_GATEWAY_URL + '/api/gw/alchemy/base-mainnet/v2',
{
method: 'POST',
headers: {
Authorization: 'Bearer ' + process.env.MODUS_GATEWAY_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'eth_getBalance',
params: ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 'latest'],
}),
}
)
const data = await res.json()The response
{ "jsonrpc": "2.0", "id": 1, "result": "0x2c68af0bb140000" }result is the balance in wei, as hex. Convert it:
const eth = Number(BigInt(data.result)) / 1e18 // 0.2What it cost
The same response tells you, in its headers:
res.headers.get('x-modus-cost-cents') // "0.15" (sub-cent, in decimal cents)
res.headers.get('x-modus-balance-cents') // your remaining creditsNo dashboard round-trip: every Gateway response carries its own receipt.
Going further
- Different job, different provider, same shape. Verified contract source comes from
/api/gw/etherscan/..., indexed history from/api/gw/thegraph/..., prices from/api/gw/mobula/..., and the auth header never changes. See Providers & credits for each provider's path shape. - Shipping a public frontend? Mint a dedicated key in Settings → Gateway keys with an origin allowlist, a provider scope, and a monthly cap, so the key in your page source can only do what you meant it to.
- Sustained bots or websockets belong on your own provider key; see the Gateway's limits.