c402

Payment Channels over HTTP 402 — Built on TON — v2.0
0
gas per request
<10ms
verification
Ed25519
off-chain crypto

Server Identity

Public Key (hex)
acdf7bed035db28c134f164343caea739f85710c7124f653959e36290f692367
Wallet Address (W5R1)
UQC0xYjlVBm1-I6qXH9Idzc7sXlEoO7IPqdmH2HNTVdyu7p9

To pay for endpoints, open a TON payment channel with this public key as party B. The server accepts channels dynamically — no pre-registration needed.

How it works

1. Open a payment channel on TON with the server's public key (one-time, ~0.04 TON gas)
2. Client sends GET /api/premium
3. Server returns 402 + PAYMENT-REQUIRED header (includes price + server public key)
4. Client signs a state update off-chain (Ed25519, <1ms) and includes channel info
5. Client retries with PAYMENT-SIGNATURE header
6. Server discovers the channel, verifies signature (<1ms, zero blockchain) → 200 OK
7. Repeat unlimited times. Close channel when done.

Endpoints

GET /api/time FREE
Current server time. No payment required.
GET /api/premium 1,000,000 nanoton
Premium content. Requires c402 payment channel.
GET /api/joke 500,000 nanoton
Random joke. Cheap entertainment.
GET /status FREE
Server status, public key, address, and pricing info.

Try it

curl http://${location.host}/api/time
curl -v http://${location.host}/api/premium
# → 402 Payment Required + PAYMENT-REQUIRED header

Protocol

Request:  GET /api/premium
Response: 402
Header:   PAYMENT-REQUIRED: base64({
            scheme: "c402",
            amount: "1000000",       // nanotons
            channelAddress: "",      // empty — client provides
            channelId: "0",          // empty — client provides
            extra: {
              publicKeyB: "acdf7bed035db28c134f164343caea739f85710c7124f653959e36290f692367"
            }
          })

Retry:    GET /api/premium
Header:   PAYMENT-SIGNATURE: base64({
            x402Version: 2,
            scheme: "c402",
            payload: {
              channelAddress: "EQ...",      // client's channel
              channelId: "123",
              state: { balanceA, balanceB, seqnoA, seqnoB },
              signature: "Ed25519...",
              publicKey: "client-hex...",
              initBalanceA: "1000000000",   // for channel discovery
              initBalanceB: "0"
            }
          })

Response: 200 OK + PAYMENT-RESPONSE header (counter-signature)
  

Links

Server Status · GitHub · Built with TON Payment Channels