Prerequisites
Before you begin, ensure that you’ve:- Set up an x402 client using
@x402/core. - Installed Node.js v18+.
- Generated an EVM wallet private key for signing.
- Funded the wallet with testnet USDC from the Circle Faucet so you can deposit into Gateway.
Steps
1
Install the SDK
CompositeEvmScheme (recommended for supporting both
payment methods), also install:2
Enable Gateway payments in your client
Pick the approach that matches your setup:
- Composite (recommended): support both Gateway and onchain payments in one client, with automatic routing based on what each server offers.
- Existing client: add Gateway to a client you’ve already configured, with minimal changes and standard onchain payments preserved.
GatewayClient directly. See the
buyer quickstart for a full
walkthrough.- Composite
- Existing client
Use No per-request routing code is needed.
CompositeEvmScheme 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.3
Fund your Gateway balance
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.Deposit time depends on the blockchain. See
required block confirmations
for exact times per blockchain.4
Verify the target server supports Gateway
Before attempting a gas-free payment, check whether the target server
supports Gateway. The If you are using
supports() method requests the target URL, checks
for a 402 response, and inspects the PAYMENT-REQUIRED header for a
compatible Gateway batching option:CompositeEvmScheme, this check is optional since the
scheme handles fallback automatically.5
Withdraw funds back to your wallet (optional)
Withdraw USDC from Gateway back to your wallet at any time. Withdrawals
are instant for both same-blockchain and crosschain destinations. The
withdraw() method calls the
Create Transfer Attestation
API endpoint:6
Look up individual 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, nonce, network,
status, token, and date range. When you filter by status, also provide
from, to, or nonce to narrow the search. This example uses the
buyer’s address as from. When network is omitted, the client defaults
to the client’s configured blockchain. See the
SDK reference for the full list of
parameters.