SDKs and examples
Two small open-source packages that wrap the official x402 libraries with Arc defaults. Use them as-is or as reference code.
x402-client
A drop-in fetch for agents. Requests that do not return 402 pass through untouched. Paid requests are checked against a per-payment cap and a running budget before anything is signed. No approvals and no gas: the wallet only needs USDC on the network it pays on.
import { createArcusClient } from '@arcusnetwork/x402-client';
const arcus = createArcusClient({
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
network: 'arc-testnet', // or 'arc'
maxPerPayment: '0.01', // USDC, refuse anything pricier
budget: '1', // USDC, stop signing after this much
onSign: (p) => console.log(`signed ${p.amount} USDC for ${p.url}`),
});
const res = await arcus.fetch('https://api.example.com/api/weather?city=Tokyo');
console.log(await res.json());
const receipt = arcus.receipt(res); // { success, transaction, explorer, ... } or null
console.log(receipt?.explorer);To read a price without paying:
import { inspect } from '@arcusnetwork/x402-client';
const quote = await inspect('https://api.example.com/api/fact');
// { paid: true, options: [{ usdc: '0.001', network: 'eip155:5042002', payTo: '0x...' }] }x402-server
An Express server with three example paid endpoints. Set PAY_TO to your wallet, run it and every route in src/routes.ts is behind a 402. Settlement happens only after your handler succeeds.
git clone https://github.com/arcusnetwork/x402-server.git
cd x402-server
npm install
cp .env.example .env # set PAY_TO
npm run dev
curl -i http://localhost:4021/api/fact
# HTTP/1.1 402 Payment RequiredAdd a route by declaring its price, then write the handler below the payment middleware:
// src/routes.ts
'GET /api/report': {
accepts: price('0.01'),
description: 'Daily report',
mimeType: 'application/json',
},Official x402 packages
Both packages sit on top of @x402/core, @x402/evm, @x402/fetch and @x402/express from the x402 project. If you already use those, the Quickstart shows the direct configuration for Arc.