How to Implement
Cross-Chain Payments
for AI Agents
Integration Example
API Usage Example// Cross-chain X402 with EIP-3009
// Complete X402 Cross-Chain Payment Flow // Access protected endpoints on Base using USDO from Polygon // STEP 1: Request Payment Requirements const endpoint = encodeURIComponent('https://api.example.com/protected'); const response = await fetch( `https://www.apifortest.shop/api/endpoint?endpoint=${endpoint}&network=polygon` ); const requirements = await response.json(); // Response (402): { accepts: [{ network, payTo, maxAmountRequired, data }] } // STEP 2: Build EIP-3009 Authorization const accept = requirements.accepts[0]; const nonce = ethers.utils.hexlify(ethers.utils.randomBytes(32)); const validAfter = Math.floor(Date.now() / 1000) - 60; const validBefore = validAfter + 3600; // Get USDO contract constants for EIP-712 const usdoContract = new ethers.Contract(accept.payTo, USDO_ABI, provider); const TYPEHASH = await usdoContract.TRANSFER_WITH_AUTHORIZATION_EXTENDED_TYPEHASH(); const DOMAIN_SEPARATOR = await usdoContract.DOMAIN_SEPARATOR(); // Build EIP-712 struct hash const structHash = ethers.utils.keccak256( ethers.utils.defaultAbiCoder.encode( ['bytes32', 'address', 'address', 'uint256', 'uint256', 'uint256', 'bytes32', 'bytes'], [TYPEHASH, wallet.address, accept.payTo, accept.maxAmountRequired, validAfter, validBefore, nonce, accept.data || '0x'] ) ); // Sign EIP-712 digest const digest = ethers.utils.keccak256( ethers.utils.solidityPack(['string', 'bytes32', 'bytes32'], ['\\x19\\x01', DOMAIN_SEPARATOR, structHash]) ); const signingKey = new ethers.utils.SigningKey(wallet.privateKey); const signature = ethers.utils.joinSignature(signingKey.signDigest(digest)); // STEP 3: Build X402 Payload const x402Payload = { x402Version: 1, scheme: 'exact', network: 'polygon', payload: { signature, authorization: { from: wallet.address, to: accept.payTo, value: accept.maxAmountRequired, validAfter, validBefore, nonce, data: accept.data } } }; // STEP 4: Execute Payment (bridge happens automatically) const result = await fetch( `https://www.apifortest.shop/api/endpoint?endpoint=${endpoint}`, { method: 'POST', headers: { 'X-Payment': btoa(JSON.stringify(x402Payload)) } } ); // STEP 5: Receive Protected Content const content = await result.json(); const paymentProof = result.headers.get('X-Payment-Response'); console.log('Access granted!', content);
Scroll to see more ↓
How It Works
2
Choose Endpoint
Pick any X402 endpoint on Base or Polygon.
3
Sign Payment
One signature using EIP-3009 standard.
4
We Route Cross-Chain
Protocol routes payment via LayerZero automatically.
5
Get Response
Receive endpoint response with settled payment.
Try It Out
Launch a live demo transaction to see Omnix402 in action. Watch as payments flow cross-chain via LayerZero.
Detailed Workflow

Need Help?
Don't hesitate to contact us if you have any issues or questions about the implementation.
@looper_d3v