In this quickstart, you will deposit USDC into a Gateway Wallet, pay for an x402-protected resource without gas fees, and check your balance. By the end, you’ll have a working client that can make gasless payments to any x402-compatible API that supports Circle Gateway.Documentation Index
Fetch the complete documentation index at: https://developers.circle.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, ensure you have:- Installed Node.js v18 or later and npm.
- An EOA (externally owned account) wallet private key for signing transactions and payment authorizations.
- Obtained testnet USDC from the Circle Faucet.
- Testnet ETH (or native gas token) for the one-time deposit transaction.
Step 1: Set up your project
1.1. Create a new project
Create a new directory and initialize a Node.js project:1.2. Install dependencies
1.3. Initialize TypeScript
Create atsconfig.json file:
tsconfig.json file:
1.4. Configure environment variables
Create a.env file in the project root and add your wallet private key:
.env
Step 2: Initialize the client
Create a new filepay.ts and initialize the GatewayClient with your chain
and private key:
pay.ts
chain parameter determines which blockchain the client connects to for
deposits and withdrawals. See the
SDK reference for all supported chain
names.
Step 3: Deposit USDC into Gateway
Before you can make gasless payments, deposit USDC from your wallet into the Gateway Wallet contract. This is a one-time onchain transaction:pay.ts
getBalances() calls the
Get Token Balances API
endpoint. The deposit itself is an onchain transaction and does not use the
Gateway API.
After the deposit confirms, your Gateway balance can be used for gasless
payments to any supported seller. See the discussion at
Fast deposits about
increasing deposit speeds.
Step 4: Pay for a resource
Add the payment logic topay.ts. Call client.pay() with the URL of an
x402-protected resource. The client handles the full payment flow automatically:
- Sends the initial request to the URL.
- Receives the
402 Payment Requiredresponse with payment details. - Signs an EIP-3009 authorization offchain (zero gas).
- Retries the request with the
PAYMENT-SIGNATUREheader.
pay.ts
pay() negotiates the 402 flow and submits the payment
through the Settle x402 Payment
API endpoint.
Step 5: Check your balance
Add balance checking after the payment using the Get Token Balances API endpoint:pay.ts
Step 6: Run the script
Run the complete script:Step 7: Withdraw funds (optional)
You can withdraw USDC from Gateway back to your wallet at any time. Same-chain withdrawals are instant. Thewithdraw() method calls the
Create Transfer Attestation
API endpoint:
pay.ts
pay.ts
Crosschain withdrawals require native gas tokens on the destination blockchain
to cover the minting transaction.
Check support before paying
Before attempting a payment, you can verify that the target URL supports Gateway batching. Thesupports() method queries the
Get Supported x402 Payment Kinds
API endpoint: