Overview
- Add nanopayments to an existing x402 client so it can pay gas-free when a server supports it, while still falling back to standard onchain payments when it does not.
- Gas-free payments require a one-time USDC deposit into a Gateway Wallet contract. After depositing, all subsequent payments are offchain signatures with zero gas cost.
- Your existing onchain payment flows continue to work unchanged. The client automatically selects the right payment method based on what the server offers.
Prerequisites
Before you begin, ensure you have:- An existing x402 client using
@x402/core. - Node.js v18+ installed.
- An EVM wallet private key for signing.
- Testnet USDC from the Circle Faucet (for Gateway deposits).
Steps
Step 1. Install the SDK
CompositeEvmScheme (recommended for supporting both payment
methods), also install:
Step 2. Choose your integration approach
Pick the option that best fits your setup.Option A: Support both Gateway and standard payments (recommended)
UseCompositeEvmScheme to route automatically based on the server’s payment
requirements. When the server offers a Gateway option, the client uses
BatchEvmScheme for a gas-free payment. When only standard onchain options are
available, it falls back to ExactEvmScheme:
CompositeEvmScheme checks each payment
option’s extra.name field and delegates to the correct scheme automatically.
Option B: Add Gateway support to an existing client
If you already have scheme registrations and want to add Gateway support with minimal changes:Option C: Gateway only
If you only need gas-free payments and don’t need standard onchain support, useGatewayClient directly. See the
buyer quickstart for a full
walkthrough.
Step 3. Deposit USDC into Gateway
Before making gas-free payments, deposit USDC from your wallet into the Gateway Wallet contract. This is a one-time onchain transaction:getBalances() calls the
Get Token Balances API
endpoint. After the deposit confirms, your Gateway balance is available for
gas-free payments to any server that supports nanopayments. See the discussion
at Fast deposits
about increasing deposit speeds.
Step 4. Check support before paying
Before attempting a gas-free payment, check whether the target server supports Gateway. Thesupports() method queries the
Get Supported x402 Payment Kinds
API endpoint:
CompositeEvmScheme, this check is optional since the scheme
handles fallback automatically.
Step 5. Understand deposit finality
When you deposit USDC into Gateway, the API waits for block confirmations before your balance becomes available. Wait times vary by blockchain:| Blockchain | Deposit time |
|---|---|
| Arc Testnet | ~0.5 sec |
| Avalanche Fuji | ~8 sec |
| HyperEVM Testnet, Sei Atlantic | ~5 sec |
| Polygon PoS Amoy, Sonic Testnet | ~8 sec |
| Arbitrum Sepolia, Base Sepolia, Ethereum Sepolia, Optimism Sepolia, Unichain Sepolia, World Chain Sepolia | ~13-19 min |
Step 6. Withdraw funds (optional)
Withdraw USDC from Gateway back to your wallet at any time. Withdrawals are instant for both same-blockchain and crosschain destinations. Thewithdraw()
method calls the
Create Transfer Attestation
API endpoint:
Step 7. Monitor transfers (optional)
After paying for resources, you can look up individual transfers using the Get x402 Transfer by ID API endpoint, or search across transfer history using the Search x402 Transfers API endpoint:searchTransfers supports filtering by sender, recipient, network, status,
token, and date range. When network is omitted, the client defaults to the
client’s configured blockchain. See the
SDK reference for the full list of
parameters.
See also
- Use nanopayments with x402 for a summary of all integration paths
- x402 seller integration for the server-side counterpart
- SDK reference for
CompositeEvmScheme,BatchEvmScheme, andregisterBatchSchemeAPI details