x402 is an HTTP 402 payment protocol. The irsb-x402 package bridges HTTP payments to on-chain IRSB receipts, providing proof of service delivery for paid API calls.
The irsb-x402 package is published. Receipt signing uses Cloud KMS. Buyer-side payments use EIP-7702 delegated signing via X402Facilitator.
npm install irsb-x402 irsbAfter verifying an x402 payment, build and post a receipt linking the payment to the service response.
import { buildReceiptV2FromX402, postReceiptV2FromX402 } from 'irsb-x402';
import { IRSBClient } from 'irsb';
const irsbClient = new IRSBClient({
chainId: 11155111,
rpcUrl: process.env.RPC_URL,
});
app.post('/api/inference', async (req, res) => {
// 1. Verify x402 payment (your existing logic)
const payment = verifyX402Payment(req);
// 2. Execute the service
const startTime = Date.now();
const result = await runInference(req.body);
const endTime = Date.now();
// 3. Build IRSB receipt from x402 context
const receipt = buildReceiptV2FromX402({
payload: {
service: 'inference-api',
payment: payment,
request: req.body,
response: result,
timing: { startTime, endTime },
},
ciphertextPointer: resultCID, // IPFS CID of full response
solverId: process.env.SOLVER_ID,
});
// 4. Post receipt on-chain
await postReceiptV2FromX402(irsbClient, receipt, solverSigner);
// 5. Return response with receipt reference
res.json({
result: result,
receipt: receipt.receiptId,
});
});import { IRSBClient } from 'irsb';
// After receiving response with receipt ID
const client = new IRSBClient({ chainId: 11155111, rpcUrl });
const receipt = await client.getReceipt(receiptId);
const isValid = await client.verifyReceipt(receiptId);
console.log('Service delivery verified:', isValid);
console.log('Evidence hash:', receipt.evidenceHash);
console.log('Timestamp:', receipt.createdAt);How x402 payment fields map to IRSB receipt fields:
| x402 Field | Receipt Field | Derivation |
|---|---|---|
| payment hash | intentHash | keccak256(payment + request) |
| service constraints | constraintsHash | keccak256(SLA terms) |
| execution path | routeHash | keccak256(service endpoint) |
| response | outcomeHash | keccak256(response body) |
| full response CID | ciphertextPointer | IPFS CID of response |
| timing data | evidenceHash | keccak256(timing + metadata) |