Tollgate

Getting started

Quickstart

Run a gateway, put a price on a route and pay for it from the command line. You need Node 20+ and a wallet with a little USDG on Robinhood Chain.

  1. Scaffold a gateway

    The init command writes a config file, a vault key and a smoke-test suite.

    terminal
    npx @tollgate/gateway init --chain 4663
    cd tollgate-gateway && npm install
  2. Price a route

    Open tollgate.config.ts and point a priced path at any upstream you control.

    tollgate.config.ts
    import { defineGateway, usdg } from "@tollgate/gateway";
    
    export default defineGateway({
      chain: { id: 4663, rpc: process.env.RPC_URL },
      payTo: process.env.PAY_TO,
      routes: {
        "/x402/premium": {
          price: usdg("0.01"),
          upstream: "http://localhost:4000/premium",
        },
      },
    });
  3. Start it and hit the gate

    Without a payment header the gateway answers with a 402 challenge describing exactly what to pay.

    terminal
    npm run dev
    curl -si http://localhost:8402/x402/premium
    response
    HTTP/1.1 402 Payment Required
    content-type: application/json
    x-payment-required: x402; scheme="exact"; network="eip155:4663"
  4. Pay and replay

    The bundled CLI signs the PaymentIntent with your key, settles it and replays the request with X-PAYMENT.

    terminal
    npx @tollgate/gateway pay http://localhost:8402/x402/premium --max 0.01

What just happened

The gateway issued a challenge with a fresh nonce and a 60-second expiry. Your client signed an EIP-712 PaymentIntent, the facilitator verified it, moved USDG on Robinhood Chain and only then forwarded the request upstream. The response carries X-PAYMENT-RESPONSE with the settlement transaction, and the console records the call against the route.