/paid returns 402 Payment Required, and a paid request returns your response and sends the funds to your payout wallet.
1. Get your credentials
In the x402Go dashboard, set up three things:- Payout wallet: your own wallet, where settled payments end up. You set it in the dashboard and never use it in code.
- API key: authenticates your server’s requests to the facilitator. It is shown only once, so copy it right away.
- Payment address: the address clients pay. It goes in
payTo. Get this from the API Keys Section if the dashboard.
2. Install dependencies
@x402/* packages. If you hit type errors, check the SDK’s installation guide for the versions it expects.
3. Configure environment variables
Find the token you want to accept in the facilitator’s supported list:asset, name, version, and assetTransferMethod from the supportedAssets list for your network. Then create .env. This example uses USDC on Celo Sepolia:
AMOUNT is in the token’s smallest unit, not a decimal amount. USDC has 6 decimals, so 10000 is 0.01 USDC. The price must also be higher than x402Go’s fee for that token, or payments are rejected.ASSET_NAME and ASSET_VERSION must match what /supported returns. Clients use them to sign the payment, and a mismatch fails with an invalid signature error.
4. Add payment middleware
Createserver.ts:
5. Run and test
402 Payment Required with the x402 payment challenge:
6. Go live
Before you accept real payments:- Check
GET /supportedfor the mainnet network and the token you want to accept. - Update
NETWORK,ASSET,ASSET_NAME,ASSET_VERSION,AMOUNT, andMETHODin your environment. Useeip155:42220for Celo mainnet. - Confirm your payout wallet in the dashboard.
- Make one small real payment, then check the transaction on a block explorer and the payout in your dashboard.
If the token’s
assetTransferMethod is permit2 (cNGN, for example), set METHOD=permit2. Payers must also approve Permit2 on that token once before their first payment, otherwise payments fail with permit2_allowance_required.Troubleshooting
When a payment is rejected,/verify returns isValid: false with an invalidReason.
A
401 response means the API key is missing or wrong.