Skip to main content
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.
Use @circle-fin/developer-controlled-wallets to fund an Arc Testnet EOA and @circle-fin/x402-batching to pay for an x402-protected resource. Smart contract account (SCA) wallets are not supported for nanopayments because Gateway verifies the EIP-3009 authorization with ecrecover. For more information, see Account types.

Prerequisites

Before you begin, ensure that you’ve:Complete the linked quickstarts before continuing. This path starts once your credentials and Arc Testnet wallet address are available. The wallet address is public configuration, so you will add it directly to pay.ts.

Step 1. Set up your project

1.1. Create the project and install dependencies

1.2. Configure TypeScript (optional)

This step is optional. It helps prevent missing types in your IDE or editor.
Create a tsconfig.json file:
Then, update the tsconfig.json file:

1.3. Set environment variables

Open .env in your editor and add:
.env
  • CIRCLE_API_KEY is your Circle API key.
  • CIRCLE_ENTITY_SECRET is your Circle entity secret.
Open .env in your editor rather than writing values with shell commands, and add .env to your .gitignore. This prevents credentials from leaking into your shell history or version control.

Step 2. Initialize the Circle Wallets client

Create pay.ts and replace the wallet address placeholder with the address from the developer-controlled wallet quickstart. Copy this block into pay.ts first.
pay.ts
BatchEvmScheme builds the EIP-3009 payment authorization. The callback normalizes its viem-style typed data for Circle Wallets by adding the explicit EIP712Domain type, serializing chainId, and converting the response to a 0x-prefixed signature. The developer-controlled wallet signs the authorization without exposing a private key to this script.

Step 3. Fund the wallet

Use the Circle Faucet to send testnet USDC to the Arc Testnet wallet address from the wallet quickstart. Arc Testnet uses USDC as its native gas token, so the faucet funds both the USDC deposit and the transaction fees.

Step 4. Deposit USDC into Gateway

Prefer a shorter deposit flow? Use Unified Balance Kit with the Circle Wallets adapter. See Deposit and spend a Unified Balance (Circle Wallets) for Arc Testnet.
Before making a nanopayment, the wallet needs USDC in its Gateway balance. The following function:
  1. Checks the current Gateway balance.
  2. Approves the Gateway Wallet contract to spend USDC.
  3. Deposits USDC into Gateway.
  4. Waits until the deposited balance is available.
Add these functions to pay.ts. They are standalone declarations, so copy them as-is below the initialization code.
pay.ts

Step 5. Pay for a resource

The first request to an x402-protected endpoint returns 402 Payment Required and a PAYMENT-REQUIRED header. Sellers often advertise Gateway options for many blockchains. Select the Arc Testnet GatewayWalletBatched option so the EIP-712 chainId matches the Circle Wallets ARC-TESTNET signer, then create the authorization and retry with a PAYMENT-SIGNATURE that includes the chosen option and the resource metadata from the 402 response.Add payForResource to pay.ts:
pay.ts

Step 6. Run the script

At the end of pay.ts, add a small entry point that calls the functions in order:
pay.ts
Start the protected endpoint from the seller quickstart before running this script. It should be available at http://localhost:3000/premium-data.
Run the script:
The seller returns the resource as soon as Gateway accepts the payment. Onchain settlement happens later when Gateway includes the payment in a batch (often several minutes). You do not need to wait for that to complete a successful pay. To inspect status later, query Search x402 Transfers with the EIP-3009 authorization nonce.