xgrain402 delivers production-ready payment processing capabilities built specifically for the BSC ecosystem
xgrain402-sdk is a growing TypeScript project in the AI payments / x402 ecosystem, focused on x402. It currently has 24 GitHub stars and 1 forks, and sits alongside related tools like nofx, ClawRouter, bitterbot-desktop, internet-court-skill, Franklin, daydreams.
Modern BSC (Binance Smart Chain) payment infrastructure for decentralized applications
xgrain402 delivers production-ready payment processing capabilities built specifically for the BSC ecosystem. This SDK enables developers to integrate sophisticated microtransaction functionality into web applications, supporting automated payment flows that scale with blockchain-native performance characteristics.
The xgrain402 SDK provides comprehensive tooling for implementing payment-gated resources using BSC's high-throughput blockchain infrastructure. Applications can leverage automated transaction processing, multi-wallet compatibility, and enterprise-grade security features without complex blockchain integrations.
Core Capabilities:
Add xgrain402 to your project using your preferred package manager:
npm install xgrain402
# or
yarn add xgrain402
# or
pnpm add xgrain402
Implement automatic payment handling in browser environments:
import { createXGrainClient } from 'xgrain402/client';
import { useAccount } from 'wagmi';
export function usePaymentClient() {
const { address, signTransaction } = useAccount();
const client = createXGrainClient({
wallet: {
address: address,
signTransaction
},
network: 'bsc-mainnet',
maxAmount: BigInt(50_000_000_000_000_000_000n), // Safety limit: 50 BNB
});
const requestPaidResource = async (endpoint: string, options?: RequestInit) => {
return await client.fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
...options,
});
};
return { requestPaidResource };
}
Configure payment verification and settlement on your backend:
import { XGrainPaymentProcessor } from 'xgrain402/server';
import { Request, Response } from 'express';
const processor = new XGrainPaymentProcessor({
network: 'bsc-mainnet',
treasuryWallet: process.env.TREASURY_WALLET_ADDRESS!,
facilitatorEndpoint: 'https://api.xgrain402.xyz/facilitator',
});
export async function handlePaymentGatedEndpoint(req: Request, res: Response) {
const incomingPayment = processor.extractPayment(req.headers);
const paymentSpec = await processor.createPaymentRequirements({
price: {
amount: "10000000000000000", // 0.01 BNB
asset: {
address: "0x0000000000000000000000000000000000000000" // Native BNB
}
},
network: 'bsc-mainnet',
config: {
description: 'API Access Fee',
resource: req.url,
}
});
if (!incomingPayment) {
const paymentRequest = processor.createPaymentRequest(paymentSpec);
return res.status(402).json(paymentRequest);
}
const verified = await processor.verifyPayment(incomingPayment, paymentSpec);
if (!verified) {
return res.status(402).json({ error: 'Invalid payment' });
}
// Execute protected business logic
const result = await processProtectedOperation(req.body);
// Complete payment settlement
await processor.settlePayment(incomingPayment, paymentSpec);
res.json({ data: result });
}
xgrain402/
├── client/
│ ├── payment-interceptor.ts # Automatic payment detection
│ ├── transaction-builder.ts # Transaction assembly
│ └── wallet-adapter.ts # Wallet interface abstraction
├── server/
│ ├── payment-processor.ts # Payment validation engine
│ ├── facilitator-client.ts # Network communication layer
│ └── middleware.ts # Framework integration utilities
├── types/
│ ├── payment-protocol.ts # Protocol schema definitions
│ ├── bsc-primitives.ts # Blockchain-specific types
│ └── client-server.ts # API interface contracts
└── utils/
├── crypto.ts # Cryptographic operations
├── validation.ts # Input sanitization
└── conversion.ts # Currency formatting
Configure your application environment with the required variables:
# BSC Network Settings
NEXT_PUBLIC_BSC_NETWORK=bsc-mainnet
NEXT_PUBLIC_BSC_RPC=https://bsc-dataseed.binance.org
# Payment Processing
TREASURY_WALLET_ADDRESS=your_treasury_bsc_address
FACILITATOR_ENDPOINT=https://api.xgrain402.xyz/facilitator
# Application Config
NEXT_PUBLIC_BASE_URL=https://your-application.com
XGRAIN_MAX_PAYMENT_AMOUNT=50000000000000000000
Configure supported BEP-20 tokens for your payment flows:
// Native BNB Configuration
const BNB_NATIVE = "0x0000000000000000000000000000000000000000";
// USDT on BSC
const USDT_BSC = "0x55d398326f99059fF775485246999027B3197955";
// BUSD on BSC
const BUSD_BSC = "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56";
const paymentConfiguration = {
price: {
amount: "10000000000000000", // 0.01 BNB
asset: { address: BNB_NATIVE }
},
network: 'bsc-mainnet'
};
Payment amounts utilize BNB wei units (18 decimal precision) represented as strings:
import { bnbToWei, weiToBnb } from 'xgrain402/utils';
// BNB to wei conversion
const subscriptionPrice = bnbToWei(0.5); // "500000000000000000"
const microPayment = bnbToWei(0.001); // "1000000000000000"
// wei to BNB conversion
const displayAmount = weiToBnb("500000000000000000"); // 0.5
Cryptographic Security:
| Provider | Integration Level | Special Features |
|---|---|---|
| MetaMask | Complete | Mobile support, auto-approval |
| Rabby | Complete | Multi-chain support |
| Trust Wallet | Complete | Mobile-first experience |
| Binance Wallet | Complete | Native BSC integration |
| Coinbase Wallet | Standard | Basic transaction signing |
| WalletConnect | Standard | Multi-wallet support |
npm run test # Complete unit test coverage
npm run test:integration # End-to-end integration testing
npm run test:e2e # Full payment flow validation
Access /xgrain-test within your application to validate:
Network Performance:
const advancedClient = createXGrainClient({
wallet,
network: 'bsc-mainnet',
customRPC: 'https://bsc-dataseed1.binance.org',
retryPolicy: {
attempts: 5,
backoff: 'exponential'
},
middleware: [
metricsMiddleware,
validationMiddleware
]
});
const batchOperations = await xgrain.processBatch([
{ endpoint: '/api/data-processing', amount: '10000000000000000' },
{ endpoint: '/api/content-access', amount: '5000000000000000' },
{ endpoint: '/api/computation-task', amount: '2500000000000000' }
]);
Compatible with modern web development stacks:
Frontend Frameworks: Next.js, React, Vue.js, Svelte
Backend Systems: Express.js, Fastify, NestJS, Koa.js
Runtime Environments: Node.js, Edge Runtime, Serverless
Blockchain Integration: Native BSC dApp compatibility
Target applications for xgrain402 implementation:
Automated Commerce: IoT device micropayments for sensor data transmission
AI Services: Autonomous agent resource consumption and service billing
Infrastructure Billing: Granular pay-per-use API and compute resource pricing
Media Distribution: Per-consumption content access and streaming payments
Service Metering: Usage-based billing models for SaaS applications
git clone https://github.com/xgrain402/xgrain402-sdk
cd xgrain402-sdk
pnpm install
pnpm build
pnpm test
MIT License
GitHub Issues: github.com/xgrain402/xgrain402-sdk/issues Twitter Updates: @xgrain402
xgrain402: Infrastructure for the decentralized economy
Your AI trading terminal assistant for US stocks, commodities, forex, and crypto.
The agent-native LLM router for autonomous agents. 55+ models (8 free), <1ms local routing, USDC payments on Base & Solana via x402.
A local-first AI agent with persistent memory, emotional intelligence, and a peer-to-peer skills economy.
The trust layer for agent-to-agent commerce — natural-language mandates, ERC-7710 delegated permissions, x402 payments, escrow, and dispute resolution as one open, catch-all Agent Skill / Claude Code plugin.
The AI agent with a wallet — spends USDC autonomously to get real work done. Apache-2.0, TypeScript.
Daydreams is a set of tools for building agents for commerce
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
Golang SDK for A2A Protocol
Client SDK for the Vybe x402 API. Pay-per-call USDC over HTTP and prepaid-credit WebSocket streaming for Vybe's Solana analytics API. Built for AI agents.
Rust SDK for the Machine Payments Protocol
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Opinionated React Native crypto x AI chat app boilerplate with embedded wallet support, conversational AI, and dynamic UI component injection