Quickstart Guide

Get started with Blocky402 in minutes. This guide walks you through making your first payment using the facilitator API. The wire format is x402 v2.

How the pieces fit

  1. A client requests a paid resource. The resource server answers 402 with a PAYMENT-REQUIRED header listing what it accepts.
  2. The client signs a payment and retries with a PAYMENT-SIGNATURE header.
  3. The resource server calls Blocky402 POST /verify and POST /settle with a JSON body, then returns the resource with a PAYMENT-RESPONSE header.

The client never calls Blocky402 itself. Steps 4 to 6 below build and send the facilitator request by hand, which is what a resource server (or its @x402/express middleware) does for you, and is useful for testing. Step 7 shows the real client and server code. Upgrading from x402 v1? See the migration guide.

Prerequisites

  • Node.js 18+ or Python 3.8+
  • A wallet with testnet tokens (for testnet)
  • Basic understanding of HTTP APIs

Step 1: Choose Your Environment

Blocky402 currently supports testnet with open access (no API key required). Mainnet support is coming soon.

Testnet Base URL: http://localhost:3002 (local) or https://api.testnet.blocky402.com (hosted)

Step 2: Check Supported Networks

# Using cURL
curl http://localhost:3002/supported
// Using Node.js
const response = await fetch('http://localhost:3002/supported');
const data = await response.json();
console.log('Supported networks:', data.kinds);
# Using Python
import requests
 
networks = requests.get('http://localhost:3002/supported').json()
print('Supported networks:', networks['kinds'])

Response:

{
  "kinds": [
    { "scheme": "exact", "network": "eip155:80002", "x402Version": 2 },
    {
      "scheme": "exact",
      "network": "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
      "x402Version": 2,
      "extra": { "feePayer": "7B6Q2MvcJvNcy1A13wHmAzmmdo3L8DVriaXML7bvkojm", "transactionVersions": [0] }
    },
    {
      "scheme": "exact",
      "network": "hedera:testnet",
      "x402Version": 2,
      "extra": { "feePayer": "0.0.7162784" }
    }
  ],
  "extensions": [],
  "signers": {
    "eip155:*": ["0xDCF7D72C2eE049DE4269ac6AAf925F33efdA18de"],
    "solana:*": ["7B6Q2MvcJvNcy1A13wHmAzmmdo3L8DVriaXML7bvkojm"],
    "hedera:*": ["0.0.7162784"]
  }
}

Step 3: Install the x402 Hedera client SDK

npm install @x402/hedera

Other families have their own SDKs: @x402/evm for any eip155:* chain and @x402/svm for Solana. This guide uses Hedera throughout.

Step 4: Build a v2 PaymentPayload

The Hedera client builds and partially signs a TransferTransaction for the payer. The facilitator co-signs as fee-payer at settlement time, so requirements.extra.feePayer is required and must match the fee-payer the facilitator advertises in GET /supported (signers["hedera:*"][0]).

// Node.js example (Hedera, exact scheme)
import { ExactHederaScheme } from '@x402/hedera/exact/client';
import { createClientHederaSigner, PrivateKey } from '@x402/hedera';
 
const paymentRequirements = {
  scheme: 'exact',
  network: 'hedera:testnet',
  amount: '100000',              // 100,000 tinybars = 0.001 HBAR
  payTo: '0.0.8011510',
  maxTimeoutSeconds: 300,
  asset: '0.0.0',                // HBAR (use a token id for HTS payments)
  extra: { feePayer: '0.0.7162784' },
};
 
const signer = createClientHederaSigner(
  '0.0.7326075',                                       // payer account id
  PrivateKey.fromStringECDSA('0xYourHederaPrivateKey'),
  { network: 'hedera:testnet' },
);
 
const scheme = new ExactHederaScheme(signer);
const signed = await scheme.createPaymentPayload(2, paymentRequirements);
 
const paymentPayload = {
  x402Version: 2,
  accepted: paymentRequirements, // v2 carries scheme and network here
  payload: signed.payload,       // { transaction: 'base64-encoded-TransferTransaction' }
};

Step 5: Verify the Payment

Your resource server does this when a request arrives with a PAYMENT-SIGNATURE header. Send a JSON body with paymentPayload and paymentRequirements.

// Node.js
const verifyResponse = await fetch('http://localhost:3002/verify', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    x402Version: 2,
    paymentPayload,
    paymentRequirements,
  }),
});
 
const verification = await verifyResponse.json();
console.log('Valid:', verification.isValid, '| Payer:', verification.payer);

Step 6: Settle the Payment

// Node.js
const settleResponse = await fetch('http://localhost:3002/settle', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    x402Version: 2,
    paymentPayload,
    paymentRequirements,
  }),
});
 
const settlement = await settleResponse.json();
console.log('Transaction:', settlement.transaction, '| Network:', settlement.network);

Step 7: Wire it into a real client and server

In production you do not call /verify and /settle yourself. The client sends PAYMENT-SIGNATURE to the resource server, and the resource server talks to Blocky402.

Client. wrapFetchWithPayment handles the 402, signs, and retries with PAYMENT-SIGNATURE:

import { wrapFetchWithPayment } from '@x402/fetch';
import { x402Client, x402HTTPClient } from '@x402/core/client';
import { ExactHederaScheme } from '@x402/hedera/exact/client';
import { createClientHederaSigner, PrivateKey } from '@x402/hedera';
 
const signer = createClientHederaSigner(
  process.env.HEDERA_ACCOUNT_ID!,
  PrivateKey.fromStringECDSA(process.env.HEDERA_PRIVATE_KEY!),
  { network: 'hedera:testnet' },
);
const client = new x402Client()
  .register('hedera:*', new ExactHederaScheme(signer))
  // HBAR is not a default asset, so the client must opt in to it. Without this
  // it refuses to pay. The cap here equals the price (0.001 HBAR).
  .setSpendControls({
    allowedAssets: [{ network: 'hedera:testnet', asset: '0.0.0', maxAmountPerPayment: '100000' }],
  });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const httpClient = new x402HTTPClient(client);
 
const response = await fetchWithPayment('http://localhost:4021/protected');
if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${await response.text()}`);
}
const data = await response.json();
 
// The settlement the resource server performed arrives in PAYMENT-RESPONSE.
const settlement = httpClient.getPaymentSettleResponse((name) => response.headers.get(name));
console.log(settlement.transaction, data);

Resource server. paymentMiddleware returns the 402, reads PAYMENT-SIGNATURE, and calls Blocky402 for you:

import express from 'express';
import { paymentMiddleware } from '@x402/express';
import { x402ResourceServer, HTTPFacilitatorClient } from '@x402/core/server';
import { ExactHederaScheme } from '@x402/hedera/exact/server';
 
const facilitator = new HTTPFacilitatorClient({ url: 'https://api.testnet.blocky402.com' });
const server = new x402ResourceServer(facilitator).register('hedera:*', new ExactHederaScheme());
 
const app = express();
app.use(
  paymentMiddleware(
    {
      'GET /protected': {
        accepts: {
          scheme: 'exact',
          network: 'hedera:testnet',
          payTo: '0.0.8011510',
          price: { amount: '100000', asset: '0.0.0' }, // 0.001 HBAR
        },
        description: 'Protected data',
      },
    },
    server,
  ),
);
app.get('/protected', (_req, res) => res.json({ ok: true }));
app.listen(4021);

Install with npm install @x402/core @x402/fetch @x402/express @x402/hedera express.

Complete Example: calling the facilitator directly

This is the facilitator side of the flow in one script: discover, build a payload, verify, settle. Use it to test an integration. A real client and resource server split this up as shown in Step 7.

import { ExactHederaScheme } from '@x402/hedera/exact/client';
import { createClientHederaSigner, PrivateKey } from '@x402/hedera';
 
const API_BASE = 'http://localhost:3002';
 
async function verifyAndSettle() {
  // 1. Discover supported networks + the facilitator's Hedera fee-payer
  const supported = await fetch(`${API_BASE}/supported`).then((r) => r.json());
  const hederaKind = supported.kinds.find((k) => k.network === 'hedera:testnet');
  if (!hederaKind) throw new Error('Facilitator does not advertise hedera:testnet');
  const feePayer = hederaKind.extra?.feePayer ?? supported.signers?.['hedera:*']?.[0];
 
  // 2. Build requirements + sign payload
  const paymentRequirements = {
    scheme: 'exact',
    network: 'hedera:testnet',
    amount: '100000',
    payTo: '0.0.8011510',
    maxTimeoutSeconds: 300,
    asset: '0.0.0',
    extra: { feePayer },
  };
 
  const signer = createClientHederaSigner(
    '0.0.7326075',
    PrivateKey.fromStringECDSA('0xYourHederaPrivateKey'),
    { network: 'hedera:testnet' },
  );
  const scheme = new ExactHederaScheme(signer);
  const signed = await scheme.createPaymentPayload(2, paymentRequirements);
 
  const paymentPayload = {
    x402Version: 2,
    accepted: paymentRequirements,
    payload: signed.payload,
  };
 
  const body = { x402Version: 2, paymentPayload, paymentRequirements };
 
  // 3. Verify
  const verify = await fetch(`${API_BASE}/verify`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  }).then((r) => r.json());
  if (!verify.isValid) {
    throw new Error(`Payment verification failed: ${verify.invalidMessage ?? verify.invalidReason}`);
  }
 
  // 4. Settle
  const settle = await fetch(`${API_BASE}/settle`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  }).then((r) => r.json());
  if (!settle.success) {
    throw new Error(`Settlement failed: ${settle.errorMessage ?? settle.errorReason}`);
  }
  console.log('Settled:', settle.transaction);
  return settle;
}

Next Steps

Need Help?