AI agent code ପାଇଁ ଡିଜାଇନ୍ କରାଯାଇଥିବା ଏକ payment API।
ଏକ ଛୋଟ REST API। ସାଇନ୍ ହୋଇଥିବା webhook। ପାଞ୍ଚଟି ଭାଷାରେ ଅଧିକାରିକ SDKs। ଏହା ଏହିପରି ତିଆରି କରାଯାଇଛି ଯେ ଆପଣଙ୍କର ଏଜେଣ୍ଟ USDC ପଠାଇପାରିବ ଏବଂ ସେଟଲ୍ କରିପାରିବ ଏବଂ କିଛି କୋଡ୍ ରେ ଭୁଗତାନଗୁଡିକୁ ସଂଖ୍ୟା କରିପାରିବ।

Blockchain0x API ଉଦ୍ଦେଶ୍ୟପୂର୍ବକ ଛୋଟ। ଆମେ ଚାହୁଁନୁ ଯେ ଆପଣ ପ୍ରଥମ payment କରିବା ପାଇଁ ଗୋଟିଏ ଘଣ୍ଟା documentation ପଢ଼ନ୍ତୁ। ଆମେ ଚାହୁଁଛୁ ଯେ ଆପଣ snippet କପି କରନ୍ତୁ, API key paste କରନ୍ତୁ, ଏବଂ ଚଳାନ୍ତୁ।
ଏକ ଛୋଟ ସର୍ଫେସ୍, ଏଜେଣ୍ଟ କୋଡ୍ ପାଇଁ ତିଆରି କରାଯାଇଛି।
payment-shaped route ଗୁଡ଼ିକ ତଳେ ଅଛି। Webhook, api-keys, ଏବଂ read-only spend-permissions surface କୁ ପୂରଣ କରେ; SDK ସବୁକୁ wrap କରେ।
/v1/paymentsAgent wallet ରୁ ଗୋଟିଏ USDC payment ପଠାନ୍ତୁ/v1/transactions/{id}ଏକ ଲେନଦେନର ସ୍ଥିତି ଏବଂ ହ୍ୟାଶ୍ ଆଣନ୍ତୁ/v1/payment-requests/{id}/settleOn-chain proof ସହ invoice settle କରନ୍ତୁ/v1/agents/{id}ଏକ ଏଜେଣ୍ଟ ୱାଲେଟ୍ ଆଣନ୍ତୁ/v1/agentsଏକ ଏଜେଣ୍ଟ ୱାଲେଟ୍ ସୃଷ୍ଟି କରନ୍ତୁସମସ୍ତ HMAC-SHA256 ସହିତ ସାଇନ୍ ହୋଇଛି।
ସହି ସ୍ଥାନରେ X-Blockchain0x-Signature ହେଡର୍। 5 ମିନିଟ୍ ରିପ୍ଲେ ଜାଲା। ପ୍ରତି POST ଉପରେ ଇଡେମ୍ପୋଟେନ୍ସୀ କୀ।
payment.receivedUSDC ଆପଣଙ୍କର ଏକ ଏଜେଣ୍ଟ ୱାଲେଟ୍ରେ ଲାଣ୍ଡ୍ ହୋଇଛି
payment.sentଆପଣଙ୍କ agent ରୁ ହୋଇଥିବା outbound payment chain ଉପରେ settle ହୋଇଥିଲା
wallet.deployedଗୋଟିଏ agent ର smart wallet deploy ହୋଇଥିଲା
webhook.testdashboard ରୁ ଆପଣ ଚାଲୁ କରିଥିବା ଗୋଟିଏ test delivery
ଆପଣଙ୍କ agent ର wallet ରୁ USDC ପଠାନ୍ତୁ।
from blockchain0x import Client
client = Client(api_key="sk_test_...") # sk_test_ testnet, sk_live_ mainnet
tx = client.payments.create(body={
"agentId": "agt_123",
"to": "0xRecipient",
"amountWei": "10000", # USDC base units (6 decimals): 0.01 USDC
})
print(tx) # may return 503 until the chain adapter is wired for your networkTypeScript ଏବଂ Python ପାଇଁ ଟାଇପ୍ କ୍ଲାଇଏଣ୍ଟଗୁଡିକ।
npm install @blockchain0x/nodeNode 18+ ସହିତ କାମ କରେ। ନେଟିଭ୍ TypeScript ପ୍ରକାର।
pip install blockchain0xPython 3.9+. ସିଙ୍କ୍ ଏବଂ ଏସିଙ୍କ୍ କ୍ଲାଇଏଣ୍ଟଗୁଡିକ।
SDK wrap କରୁଥିବା request body ଗୁଡ଼ିକ।
ଏଗୁଡିକ ପ୍ରତ୍ୟେକ route ପାଇଁ verified inputs। ଏଠାରେ responses ସଂକ୍ଷିପ୍ତ ଭାବେ ଦେଖାଯାଇଛି; full typed shapes SDK ଏବଂ API reference ରେ ଅଛି। Amounts ହେଉଛି USDC base units (6 decimals)।
/v1/paymentsଗୋଟିଏ USDC payment ପଠାନ୍ତୁ (payments.create)। amountWei ହେଉଛି USDC base units (6 decimals)। chain adapter wire ହେବା ପର୍ଯ୍ୟନ୍ତ 503 ଫେରାଇପାରେ।
{
"agentId": "agt_123",
"to": "0xRecipient",
"amountWei": "10000",
"metadata": { "reason": "Research report" }
}{
"txHash": "0xff5...e12"
}/v1/payment-requests/{id}/settleDashboard ରେ ସୃଷ୍ଟି ହୋଇଥିବା payment request (invoice) କୁ on-chain proof ସହ settle କରନ୍ତୁ (paymentRequests.settle)। create route ନାହିଁ - କେବଳ settle।
{
"txHash": "0xff5...e12",
"payerAddress": "0xBuyer...",
"amountUsdcVerified": "0.10"
}{
"txHash": "0xff5...e12"
}/v1/transactions/{id}ID (transactions.get) ଦ୍ୱାରା ଏକ ଏକକ ଲେନଦେନ ଆଣନ୍ତୁ।
(no body){
"id": "tx_01J9...",
"txHash": "0xff5...e12"
}/v1/agents/{id}ଏକ ଏଜେଣ୍ଟ ୱାଲେଟ୍ (agents.get) ଆଣନ୍ତୁ। ଏହାର ସାଧାରଣ ପୃଷ୍ଠା wallet.blockchain0x.com/a/{slug} ରେ ଅଛି।
(no body){
"id": "agt_01J9QKE...",
"name": "research-bot",
"public_url": "https://wallet.blockchain0x.com/a/research-bot"
}/v1/agents/{id}/spend-permissionsAgent ର spend permissions ପଢ଼ନ୍ତୁ। API ମାଧ୍ୟମରେ READ-ONLY - creation ଏବଂ changes କେବଳ dashboard ରେ।
(no body){
"allowance_wei": "5000000",
"per_tx_wei": "1000000",
"period_seconds": 86400,
"start_at": "2026-05-15T00:00:00Z",
"revoked_at": null
}ପେଲୋଡ୍ କୁ ବିଶ୍ୱସ୍ତ କରିବା ପୂର୍ବରୁ ସାଇନ୍ ଯାଞ୍ଚ କରନ୍ତୁ।
କେହି ତୁମର କଲ୍ବ୍ୟାକ୍ URL କୁ POST କରିପାରିବ। ସହିତା ହେଉଛି ଯାହା ସତ୍ୟରେ ଘଟଣା ଆମରୁ ଆସିଛି।
ପ୍ରତି ଡେଲିଭରୀ ଏକ ନେଇଯାଏ X-Blockchain0x-Signature header (t=<unix>,v1=<hex>) - `${t}.${rawBody}` string ଉପରେ ଆପଣଙ୍କ webhook secret ସହିତ ଏକ HMAC-SHA256, 5-minute replay window ଭିତରେ। Node ରେ, @blockchain0x/node ର webhooks.verify ଏହା କରେ ଏବଂ ଆପଣ branch କରିପାରିବା ଏକ discriminated union ଫେରାଇଦିଏ। ଅନ୍ୟ ଭାଷାରେ, ସେହି HMAC ଗଣନା କରନ୍ତୁ ଏବଂ constant time ରେ compare କରନ୍ତୁ। RAW body ପଢ଼ନ୍ତୁ, parsed copy ନୁହେଁ - re-serializing କଲେ signature ଭାଙ୍ଗିଯାଏ।
import express from "express";
import { webhooks } from "@blockchain0x/node";
const app = express();
// Capture the RAW body. The HMAC is over the exact bytes on the wire.
app.use(express.raw({ type: "application/json" }));
app.post("/webhooks/payment", (req, res) => {
const result = webhooks.verify({
headers: req.headers,
rawBody: req.body, // Buffer, raw bytes
secret: process.env.BLOCKCHAIN0X_WEBHOOK_SECRET!,
});
if (!result.ok) return res.status(400).json({ code: result.code });
// result.eventType is "payment.received" | "payment.sent" | ...
handleEvent(result);
res.status(200).send("ok");
});import hmac, hashlib, os, time
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["BLOCKCHAIN0X_WEBHOOK_SECRET"].encode()
@app.post("/webhooks/payment")
def receive():
raw = request.get_data() # RAW bytes - do not parse first
sig = request.headers.get("X-Blockchain0x-Signature", "")
ts = request.headers.get("X-Blockchain0x-Timestamp", "")
# Header is "t=<unix>,v1=<hex>"; some proxies send bare hex + the ts header.
parts = dict(p.split("=", 1) for p in sig.split(",") if "=" in p)
t, v1 = parts.get("t", ts), parts.get("v1", sig)
want = hmac.new(SECRET, t.encode() + b"." + raw, hashlib.sha256).hexdigest()
if not hmac.compare_digest(want, v1) or abs(time.time() - int(t)) > 300:
abort(401)
handle_event(request.headers.get("X-Blockchain0x-Event-Type"), request.get_json())
return "ok", 200webhook create କିମ୍ବା rotate କରିବାବେଳେ (webhooks.rotateSecret) webhook secret ଗୋଟିଏଥର ଫେରାଇ ଦିଆଯାଏ, ଏବଂ BLOCKCHAIN0X_WEBHOOK_SECRET ହେଉଛି ଯେଉଁଠାରୁ ଆପଣଙ୍କ handler ଏହାକୁ ପଢ଼େ। Rotate କଲେ ପୁରୁଣା secret invalid ହୋଇଯାଏ, ସେହିପାଇଁ rollout ସମନ୍ୱୟ କରନ୍ତୁ: ନୂତନ secret କୁ ଆପଣଙ୍କ server ର env ରେ set କରନ୍ତୁ, deploy କରନ୍ତୁ, ତାପରେ rotate କରନ୍ତୁ। shipped event ଗୁଡ଼ିକ ହେଉଛି payment.received, payment.sent, wallet.deployed, ଏବଂ webhook.test - event type ଉପରେ branch କରନ୍ତୁ, ଅନ୍ୟ ସବୁକୁ ignore କରନ୍ତୁ।
ସୁରକ୍ଷିତ ଭାବେ ପୁଣି ଚେଷ୍ଟା କରନ୍ତୁ। API ଦୁଇଥର ଦେୟ କରିବ ନାହିଁ।
ଏଜେଣ୍ଟ କୋଡ୍ ପୁନର୍ବାର ଚେଷ୍ଟା। ନେଟୱର୍କ୍ଗୁଡିକ ସଂଯୋଗ ଛାଡ଼ିଦେଇଥାଏ। LLMs ଟୁଲ୍କୁ ଦୁଇଥର କଲ୍ କରିବାକୁ ନିଷ୍ପତ୍ତି ନେଉଛି। ଏହାକୁ ସୁରକ୍ଷିତ କରିବାକୁ, ପଠାନ୍ତୁ ଏକ Idempotency-Key POST ଉପରେ header. SDK ର payments.create ଆପଣଙ୍କ ପାଇଁ ସ୍ୱୟଂଚାଳିତ ଭାବେ ଏକ stable one mint କରେ, ତେଣୁ retry କଲାପରେ call ଟି ଦୁଇଥର ପେମେଣ୍ଟ କରିବା ପରିବର୍ତ୍ତେ ଏକେ on-chain submission ରେ collapse ହୋଇଯାଏ। ଏକେ logical operation କୁ processes ମଧ୍ୟରେ dedupe କରିବାକୁ ଚାହିଲେ ନିଜ key ସହିତ override କରନ୍ତୁ।
curl -X POST https://api.blockchain0x.com/v1/payments \
-H "Authorization: Bearer $BLOCKCHAIN0X_API_KEY" \
-H "Idempotency-Key: 8e2c3a40-pay-vendor-once" \
-H "Content-Type: application/json" \
-d '{ "agentId": "agt_123", "to": "0xRecipient", "amountWei": "10000" }'- ପ୍ରଥମ କଲ୍: payment କୁ submit କରେ, transaction ଫେରାଏ।
- ସେହି key ସହ ପୁଣି ଚେଷ୍ଟା କରନ୍ତୁ: ଦୁଇଥର ଭୁଗତାନ କରିବା ପ୍ରତିବଦଳରେ ଗୋଟିଏ on-chain submission କୁ ସଙ୍କୋଚିତ ହୋଇଯାଏ।
- SDK ଏହାକୁ handle କରେ: payments.create ସ୍ୱୟଂଚାଳିତ ଭାବରେ ଗୋଟିଏ stable Idempotency-Key ସୃଷ୍ଟି କରେ, ସେଥିପାଇଁ retried call default ରୁ ନିରାପଦ।
- ଏହାକୁ ଓଭର୍ରାଇଡ୍ କରନ୍ତୁ: ବିଭିନ୍ନ process ମଧ୍ୟରେ ସେହି ଏକେ logical operation କୁ dedupe କରିବାକୁ ଚାହିଲେ ନିଜର key ପଠାନ୍ତୁ।
ସୁପାରିଶିତ pattern ହେଉଛି ଆପଣଙ୍କ agent code ରେ ପ୍ରତ୍ୟେକ logical operation ପାଇଁ ଗୋଟିଏ UUID generate କରିବା (ଉଦାହରଣ, "order Y ପାଇଁ vendor X କୁ pay କରିବା" ପାଇଁ ଗୋଟିଏ UUID) ଏବଂ operation ସଫଳ ହେଉଅବଧି retries ମଧ୍ୟରେ ଏହାକୁ reuse କରିବା। ଆପଣ specify ନକଲେ official SDKs payments.create ପାଇଁ ସ୍ୱୟଂଚାଳିତଭାବେ ଗୋଟିଏ auto-generate କରେ।
ଆପଣଙ୍କ limit response ରୁ ପଢ଼ନ୍ତୁ, ଟେବୁଲ୍ ରୁ ନୁହେଁ।
Limits ଆପଣଙ୍କ plan ସହିତ scale ହୁଏ। ବଦଳିଯାଉଥିବା numbers କୁ hard-code କରିବା ପରିବର୍ତ୍ତେ, ପ୍ରତ୍ୟେକ response ଆପଣ କେଉଁ ସ୍ଥାନରେ ଅଛନ୍ତି ତାହା କହେ ଏବଂ SDKs backoff ଆପଣଙ୍କ ପାଇଁ handle କରେ।
ପ୍ରତ୍ୟେକ ସଫଳ ପ୍ରତିକ୍ରିୟାରେ ହେଡର୍ଗୁଡିକ
X-RateLimit-Limit: ଆପଣଙ୍କର ପ୍ଲାନର ସ୍ଥିର ଦରX-RateLimit-Remaining: ଏହି ୱିଣ୍ଡୋରେ କେତେ କଲ୍ ବାକୀ ଅଛିX-RateLimit-Reset: ଯେତେବେଳେ ୱିଣ୍ଡୋ ପୁନସ୍ଥାପିତ ହୁଏ ସେତେବେଳେ ୟୁନିକ୍ ସେକେଣ୍ଡ୍
ଯେତେବେଳେ ଆପଣ କ୍ୟାପ୍ କୁ ହିଟ୍ କରନ୍ତି (HTTP 429)
- ପ୍ରତିକ୍ରିୟାରେ ଅନ୍ତର୍ଗତ ଅଛି
Retry-Afterସେକେଣ୍ଡରେ - official SDKs 429 ଏବଂ 5xx ଉପରେ exponential backoff ସହିତ retry କରେ, Retry-After କୁ ମାନିକରି
- ଅଧିକାଂଶ code 429 କୁ ହାତେ handle କରେନାହିଁ କାରଣ SDK ପୂର୍ବରୁ ଏହା କରେ
x402 ଫ୍ଲୁଏଣ୍ଟ୍ ଭାବେ କଥା ହୁଏ। ଏହା ବିନା ମଧ୍ୟ କାମ କରେ।
x402 ହେଉଛି HTTP-native payments ପାଇଁ open protocol। ମୂଳ ଧାରଣା: 402 Payment Required ଫେରାଇଥିବା ଯେକୌଣସି API response ଭିତରେ payment requirements ଘୋଷଣା କରିପାରେ, ଏବଂ spec ବୁଝୁଥିବା ଯେକୌଣସି client pay କରି retry କରିପାରେ - signup ନାହିଁ, API key ନାହିଁ, out-of-band negotiation ନାହିଁ। Blockchain0x ସତ୍ୟ x402 packages ଦିଏ: ଗୋଟିଏ pay-side client ଏବଂ receive-side server adapters। ଆଜିର ଏକମାତ୍ର scheme ହେଉଛି exact-usdc, on Base।
HTTP/1.1 402 Payment Required
Content-Type: application/json
{
"version": 1,
"resource": "https://api.example.com/paid-endpoint",
"accepts": [
{ "scheme": "exact-usdc", "network": "eip155:8453" }
]
}ଏଜେଣ୍ଟ କଲର୍ କଣ କରେ
- 402 body ପଢ଼େ: version 1, resource, ଏବଂ payment requirements ର non-empty accepts[] (scheme exact-usdc, network eip155:8453 for Base).
- ଏକ payment build କରେ ଏବଂ X-Payment: exact-usdc:<base64(json)> header ସହ request କୁ ପୁନଃପ୍ରେଷଣ କରେ।
- pay side ରେ, @blockchain0x/x402 ର createX402Client({ sdk }) ଏହାକୁ ଆପଣଙ୍କ ପାଇଁ କରେ - ଏହା 402s କୁ ସ୍ୱୟଂଚାଳିତ ଭାବରେ ଉତ୍ତର ଦିଏ।
- ଆପଣଙ୍କ server X-Payment header ଯାଞ୍ଚ କରେ ଏବଂ original request ପୂରଣ କରେ।
ଦୁଇପକ୍ଷ, ବାସ୍ତବିକ ପ୍ୟାକେଜ୍
ଦେୟ ପାଇଁ, createX402Client({ sdk }) @blockchain0x/x402 ରୁ fetch କୁ wrap କରେ ଏବଂ 402 କୁ ସ୍ୱୟଂଚାଳିତ ଭାବେ ଉତ୍ତର ଦେଇଥାଏ। ଗ୍ରହଣ ପକ୍ଷରେ, createX402Plugin (Fastify) ଏବଂ createX402Middleware (Express) ଆପଣଙ୍କ ନିଜ endpoints କୁ gate କରନ୍ତୁ। କିମ୍ବା x402 କୁ ଛାଡ଼ି ସିଧା REST API ବ୍ୟବହାର କରନ୍ତୁ - ଦୁଇଟି ଏକସାଥିରେ କାମ କରେ, ସେଥିପାଇଁ ଆପଣ ପ୍ରସ୍ତୁତ ହେଲେ x402 ଯୋଡ଼ିପାରିବେ।