On-Chain Payments
Accept cryptocurrency payments on EVM-compatible blockchains. FluxKit monitors the blockchain for incoming payments and automatically confirms them.
Configuration
pay({
onchain: {
rpcUrl: process.env.RPC_URL,
receiverAddress: process.env.PAYMENT_WALLET,
supportedTokens: ["USDC", "USDT", "ETH"],
supportedChains: ["ethereum", "arbitrum", "base"],
confirmations: 3, // Required block confirmations
pollInterval: 15_000, // Check every 15 seconds
tokenAddresses: {
USDC: {
ethereum: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
arbitrum: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
base: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
USDT: {
ethereum: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
arbitrum: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
},
},
},
});
Creating a Payment Request
Programmatic
const payment = await app.pay.onchain.createPayment({
amount: "29.99",
token: "USDC",
chain: "arbitrum",
metadata: {
userId: "user-123",
orderId: "order-456",
},
expiresIn: "30m",
});
console.log(payment._id); // Payment ID
console.log(payment.receiverAddress); // Wallet address to pay
console.log(payment.amount); // "29990000" (in token decimals)
console.log(payment.token); // "USDC"
console.log(payment.chain); // "arbitrum"
console.log(payment.status); // "pending"
REST API
curl -X POST http://localhost:3000/pay/onchain/payment \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGci..." \
-d '{
"amount": "29.99",
"token": "USDC",
"chain": "arbitrum"
}'
Response (200):
{
"_id": "65a1b2c3d4e5f6a7b8c9d0e1",
"receiverAddress": "0x1234...5678",
"amount": "29990000",
"displayAmount": "29.99",
"token": "USDC",
"tokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
"chain": "arbitrum",
"status": "pending",
"expiresAt": "2025-01-15T11:00:00.000Z"
}
Checking Payment Status
Programmatic
const status = await app.pay.onchain.getPayment(paymentId);
if (status.status === "completed") {
console.log(`Payment confirmed in tx ${status.txHash}`);
}
REST API
curl http://localhost:3000/pay/onchain/payment/65a1b2c3d4e5f6a7b8c9d0e1 \
-H "Authorization: Bearer eyJhbGci..."
Response (200) -- confirmed:
{
"_id": "65a1b2c3d4e5f6a7b8c9d0e1",
"status": "completed",
"amount": "29990000",
"token": "USDC",
"chain": "arbitrum",
"txHash": "0xabc123...",
"blockNumber": 12345678,
"confirmations": 5,
"completedAt": "2025-01-15T10:35:00.000Z"
}
Payment Events
app.pay.onchain.on("payment.confirmed", async (payment) => {
console.log(`Payment ${payment._id} confirmed`);
// Fulfill the order
});
app.pay.onchain.on("payment.expired", async (payment) => {
console.log(`Payment ${payment._id} expired`);
});
Supported Tokens
| Token | Decimals | Chains |
|---|---|---|
| ETH | 18 | Ethereum, Arbitrum, Base |
| USDC | 6 | Ethereum, Arbitrum, Base |
| USDT | 6 | Ethereum, Arbitrum |
Environment Variables
| Variable | Default | Description |
|---|---|---|
RPC_URL | -- | Default EVM RPC endpoint |
PAYMENT_WALLET | -- | Receiver wallet address |
ONCHAIN_CONFIRMATIONS | 3 | Required confirmations |
ONCHAIN_POLL_INTERVAL | 15000 | Polling interval in ms |