Skip to content
Turnstile

Integrate

One middleware line with a price.

Sellers add a route with a price; buyers use a client with a spending policy. Both are in the repo and run today against the live facilitator.

Sell an API

import { Hono } from "hono";
import { Seller, honoPaid } from "@turnstile/seller";

const seller = new Seller({ slug: "my-api", chainId: "qorechain-diana", rollupId: "turnstile-1", rest, identity, payTo,
  facilitatorUrl: "https://facilitator-production-7f4aa7c5.up.railway.app", facilitatorToken, quotes });

app.get("/v1/answer/:q", honoPaid(seller, { key: "answer", priceUqor: "120000", description: "My answer" },
  async (c) => ({ body: await compute(c.req.param("q")) })));   // unpaid callers get HTTP 402 with a signed quote

Pay for one

import { Buyer } from "@turnstile/buyer";

const buyer = new Buyer({ role: "buyer-a", policy: { perCallMaxUqor: 100_000n, dailyMaxUqor: 5_000_000n, allowSellers: ["qor1…"] } });
const r = await buyer.fetch("https://api.example.com/v1/answer/42");   // 402 → pay → sealed answer opened locally
console.log(r.data, r.paid?.l1Tx);

The wire format is x402 v2 (PAYMENT-REQUIRED, PAYMENT-SIGNATURE, PAYMENT-RESPONSE) on network cosmos:qorechain-diana, so any x402 client can pay by adding our scheme.

Charge MCP callers

# a HOSTED MCP server that charges per tool call (x402 over MCP)
curl -s -X POST https://sellers-production-9b830a21.up.railway.app/mcp -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

# pay and call from your agent (opens the answer sealed to your key)
import { Buyer, payMcp } from "@turnstile/buyer";
const r = await payMcp(new Buyer({ role: "buyer-a" }), "https://sellers-production-9b830a21.up.railway.app/mcp", "pq_readiness", { address: "qor1…" });

Limit an agent on chain

// an owner with a registered ML-DSA-87 key sets the agent's limit on chain (EVM tx); the facilitator then refuses payments that break it
AgentSpendCap(0x16c2cb5600d37195C88fde5327771652b1d02dFd).setPolicy(agentAccountId, perCallUqor, dailyUqor, expiresAt, sellerPayToIds);
// anyone can read or test it: GET /api/v1/cap/policy/:agent   GET /api/v1/cap/check?agent=&seller=&amount=

Spend caps · zero-knowledge fee audit · exit files · fee split

Source: packages/seller · packages/buyer · the x402 binding spec (TRD)