How It Works
- Your client sends a request to a Dune API endpoint.
- Dune responds with HTTP 402 and a
WWW-Authenticate: Paymentchallenge describing the cost. - The
mppxclient library automatically opens a Tempo payment channel on the first 402, depositing funds into an on-chain escrow. - Subsequent requests are authenticated with signed channel vouchers deducted from the deposit.
- When you are done, you close the channel and any unspent deposit is returned to your wallet.
Available Endpoints
| Endpoint | Description |
|---|---|
POST /v1/sql/execute | Execute a SQL query |
GET /v1/execution/:execution_id/results | Fetch JSON results for an execution |
GET /v1/execution/:execution_id/csv | Download CSV results for an execution |
Integration Guide
This walkthrough uses themppx client library and viem for EVM account management. The mppx session API wraps the standard fetch and handles the 402 negotiation, channel management, spend tracking, and payment signing transparently.
Step 1 - Install dependencies
Step 2 - Set up your wallet and initialize a session
Create an account from a private key and initialize a Tempo session. ThemaxDeposit parameter sets the maximum amount (in USD) to escrow when a payment channel is opened.
Step 3 - Execute a query
Usesession.fetch exactly like the standard Fetch API. On the first call, the session intercepts the 402 response, opens a Tempo payment channel, and retries the request with a valid payment credential - all transparently.
Step 4 - Poll until the query completes
Dune executes queries asynchronously. Poll the status endpoint until the state isQUERY_STATE_COMPLETED.
Step 5 - Fetch results
Once the query completes, retrieve the results. Each request is automatically paid through the open channel.Step 6 - Close the payment channel
When you are finished, close the channel to settle on-chain and reclaim any unspent deposit. The session tracks spending automatically and only pays for what you used.Learn More
mppxclient library - TypeScript SDK for MPP- paymentauth.org - protocol specifications and registry
- Dune API Reference - full list of available API endpoints