A step-by-step guide to implementing the x402 HTTP 402 Payment Required pattern on a Cosmos SDK chain using ClawPurse Gateway and NTMPI tokens — no EVM, no facilitator, no custody.
Everyone's talking about x402 — the open payment protocol that brings HTTP 402 Payment Required back from the dead. Coinbase launched it, Cloudflare joined the foundation, Vercel shipped middleware for it, and Circle demoed AI agents autonomously paying for API calls.
But here's the thing: every x402 implementation so far runs on EVM chains (Base, Polygon, Solana) and settles in stablecoins through a centralized facilitator.
What if you're building on Cosmos? What if you're a DePIN node operator who already earns and stakes a native token? What if you want to self-host the whole stack with no facilitator dependency?
That's what ClawPurse does. It implements the same x402 pattern — 402 invoice → on-chain payment → retry with proof — on the Neutaro blockchain (Cosmos SDK) with NTMPI tokens. No facilitator. No custody. Fully self-hosted.
Here's how to set it up in under 5 minutes.
What we're building
A gated API where:
- Any request to a protected endpoint returns
402 Payment Requiredwith an invoice - The caller (human, script, or AI agent) pays on-chain with NTMPI
- The caller retries with an
X-Payment-Proofheader - The gateway verifies the payment on Neutaro and proxies to your upstream API
This is the exact x402 flow. The only difference from Coinbase's version: we verify directly against the Neutaro REST API instead of routing through a facilitator.
Prerequisites
- Node.js 18+
- A Neutaro wallet address (we'll create one)
- Docker (optional, for gateway deployment)
Step 1: Install the ClawPurse agentic wallet
ClawPurse is a local-only CLI wallet with encrypted keystores and guardrails built for autonomous agents.
git clone https://github.com/mhue-ai/ClawPurse.git
cd ClawPurse
npm install && npm run build && npm link
# Create a wallet
clawpurse init --password yourpassword
# Get your address
clawpurse address
# → neutaro1abc...xyz
# Check balance
clawpurse balance --password yourpassword
Need tokens? Grab free NTMPI from the Timpi Drip faucet — it uses proof-of-work instead of CAPTCHA, so it works for AI agents too.
Step 2: Deploy the 402 gateway
git clone https://github.com/mhue-ai/clawpurse-gateway.git
cd clawpurse-gateway
npm install
cp .env.example .env
Edit .env:
PORT=4020
GATEWAY_UPSTREAM=http://localhost:3000
GATEWAY_PAYMENT_ADDRESS=neutaro1abc...xyz # your address from step 1
GATEWAY_DEFAULT_PRICE=0.001 # price per request in NTMPI
JWT_SECRET=your-random-secret
Start a test upstream (the gateway includes one):
npm run test:upstream
Start the gateway:
npm run dev
That's it. Your API is now gated behind NTMPI micropayments.
Step 3: Test the x402 flow
# Hit the gated endpoint
curl http://localhost:4020/api/test
You get back:
{
"error": "Payment required",
"payment": {
"invoiceId": "inv_abc123",
"amount": "0.001",
"address": "neutaro1abc...xyz",
"memo": "inv_abc123"
}
}
Pay with ClawPurse:
clawpurse send neutaro1abc...xyz 0.001 \
--memo inv_abc123 \
--password yourpassword \
--yes
Retry with proof:
curl -H "X-Payment-Proof: inv_abc123" \
http://localhost:4020/api/test
→ 200 OK with your upstream data. Done.
How this compares to Coinbase x402
| Coinbase x402 | ClawPurse Gateway | |
|---|---|---|
| Chain | Base, Polygon, Solana | Neutaro (Cosmos SDK) |
| Token | USDC, ERC-20s | NTMPI |
| Verification | Centralized facilitator | Direct on-chain query |
| Header | X-PAYMENT |
X-Payment-Proof |
| Wallet | Coinbase Agentic Wallets | ClawPurse CLI + API |
| Deploy | SDK/middleware | Docker or bare metal |
| Custody | Facilitator-mediated | Zero custody, self-hosted |
The key architectural difference: Coinbase x402 uses a facilitator — a server that verifies and settles payments on behalf of the resource server. ClawPurse skips this entirely. The gateway queries the Neutaro REST API directly (/cosmos/tx/v1beta1/txs) to verify the payment amount, memo, and block confirmations.
This means:
- No trust dependency on a third-party facilitator
- No rate limits from facilitator API calls
- No registration — deploy and go
Making it agent-friendly
The whole point of x402 is that machines can pay for things. Here's a Python agent that handles the 402 flow autonomously:
import requests, subprocess
def paid_fetch(url):
res = requests.get(url)
if res.status_code == 402:
inv = res.json()["payment"]
# Pay with ClawPurse
subprocess.run([
"clawpurse", "send",
inv["address"], inv["amount"],
"--memo", inv["memo"], "--yes"
])
# Retry with proof
res = requests.get(url, headers={
"X-Payment-Proof": inv["invoiceId"]
})
return res.json()
data = paid_fetch("http://gateway:4020/api/data")
ClawPurse also includes guardrails specifically designed for agent autonomy:
- Spending limits — cap how much an agent can send per transaction or per day
- Destination allowlists — restrict which addresses an agent can pay
- Confirmation thresholds — require N block confirmations before considering payment settled
Configure these with the guardrail wizard:
clawpurse guardrails --password yourpassword
Prepaid balances for high-frequency agents
For agents making hundreds of API calls, paying on-chain every time is wasteful. ClawPurse Gateway supports prepaid balances — deposit once, then make many calls:
# Enable in .env
GATEWAY_PREPAID=true
The agent deposits NTMPI once:
curl -X POST http://localhost:4020/prepaid/deposit \
-H "Content-Type: application/json" \
-d '{"txHash": "ABC123...", "clientId": "agent-001"}'
Then subsequent requests just include the client ID:
curl -H "X-Client-Id: agent-001" \
http://localhost:4020/api/data
The gateway deducts from the balance per call. No repeated on-chain transactions.
Route-level pricing
Not all endpoints are equal. Charge more for writes, less for reads:
GATEWAY_ROUTES={"POST /api/generate":0.01,"GET /api/status":0.0001}
Default price applies to everything else.
Why this matters for DePIN
DePIN operators run real infrastructure — GPU rigs, storage nodes, wireless hotspots, weather stations, dashcams. But monetizing that infrastructure usually means signing up for a platform, waiting for payouts, and dealing with fiat rails that weren't built for machines.
ClawPurse flips that. Any HTTP endpoint becomes a paid service with one Docker command.
Imagine:
You rent out spare GPU compute for AI inference — agents pay per request, settled on-chain in seconds
You run a sensor network and sell environmental data — 0.001 NTMPI per API call, no subscription required
You host a proxy or VPN exit node — pay-per-session with no account signup
You offer geolocation or mapping data from your fleet — agents query and pay automatically
No payment processor. No platform cut. No waiting 30 days for a bank transfer. Just an HTTP endpoint, a price, and on-chain settlement.
That's the micropayment layer DePIN has been missing — and x402 is the protocol that makes it work.
Resources
- x402 landing page: clawpurse.ai/x402
- Gateway docs: gateway.clawpurse.ai
- Wallet repo: github.com/mhue-ai/ClawPurse
- Gateway repo: github.com/mhue-ai/clawpurse-gateway
- Agent integration (SKILL.md): github.com/mhue-ai/ClawPurse/blob/main/SKILL.md
- Free NTMPI: drip.clawpurse.ai
- Tax tracking: ledger.clawpurse.ai
- Coinbase x402 spec: x402.org
- OpenClaw AI framework: mhue.ai
ClawPurse is open source (MIT) and maintained by the Mhue family. If it's saving you time, tip the builders.
Top comments (0)