Agent to Paid API: Substreams → database → API → x402

Agent to Paid API: Substreams → database → API → x402

<aside> 🚀

One prompt in, one paid endpoint out, with every command checked against official docs.

Build a Substream with agent skills, sink it into your own database, and charge per call with x402 on any supported chain. Worked example: Jupiter Lend (jupiter-lend-substreams).

</aside>

At a glance

Item Detail
Steps 9, from installing skills to publishing
Payments Any chain: whatever your facilitator supports
Database Any host: Railway, your server, or managed
Sink 1 CLI: substreams sink postgres
Worked example Jupiter Lend on Solana (jupiter-lend-substreams)

Who this is for

<aside> 🤖

AI agents

Grok Bot, Claude Code, Cursor: follow the steps in order and ask a human before any spend or publish.

</aside>

<aside> 🧱

Data builders

Substreams developers who want their package to earn per call instead of sitting in a registry.

</aside>

<aside> 💸

API sellers

Anyone who wants fresh on-chain tables behind a 402 paywall without running an indexer from scratch.

</aside>

What you'll build

Plain-English prompt
   │  agent skills
   ▼
Substreams package (db_out)
   │  sink
   ▼
Postgres / ClickHouse (Railway or your own server)
   │  SQL
   ▼
Hono API (read-only)
   │  402 then pay
   ▼
x402 paywall (USDC on any supported chain)

No single public repo covers this whole path today. StreamingFast's skills cover build, test and sink; the x402 docs cover the paywall. This guide joins them, with lessons from running the Jupiter Lend API on Railway.

Resource Build Test Sink API x402
substreams-skills ✅ ✅ ✅ — —
Graph docs skills page Setup — — — —
StreamingFast AI indexer blog ✅ Basic — — —
SQL sink migration guide — — ✅ — —
x402 seller quickstart — — — ✅ ✅
This guide ✅ ✅ ✅ ✅ ✅

Prerequisites

Item Details
CLI The substreams CLI, a recent version that includes substreams sink postgres
Data key A Substreams API key (StreamingFast / The Graph Market, or Pinax) in SUBSTREAMS_API_TOKEN or SUBSTREAMS_API_KEY, or a .substreams.env file
Build tools Rust with the wasm32-unknown-unknown target, and buf for protobuf
API Node.js 20+ for Hono and the @x402/* packages
Hosting Railway or your own server (Docker on a box or VPS); plan for disk, see step 4
Wallets A receiving address on each chain you accept (EVM, Solana or another network your facilitator supports); public addresses only
Agent Grok Bot, Claude Code, Cursor or VS Code 1.107+

<aside> 🔐

Secrets rule: Never paste API keys, database URLs, wallet keys or salts into chat, logs, READMEs or the Page. Keep them in Railway variables or a local env file that is git-ignored.

</aside>


1. Install the agent skills

Goal: give your agent the Substreams skills before it writes any code.

  1. Claude Code: run the two commands below, then check with /skills.

    claude plugin marketplace add streamingfast/substreams-skills
    claude plugin install substreams-dev@streamingfast-substreams
    
  2. Load without installing: clone the repo, then point Claude Code at it.

    git clone https://github.com/streamingfast/substreams-skills.git
    claude --plugin-dir ./substreams-skills