Skip to main content
This guide walks you through calling a live x402-protected route on the Meterlane public sandbox. Your agent client will receive an HTTP 402, sign a USDC payment, and automatically retry — getting back HTTP 200 with the response body. The whole flow runs on Base Sepolia with test USDC, so no real funds are involved.
1

Sign up and create an org

Go to meterlane.app and sign up. During onboarding you will create your first org — this is your tenant namespace in Meterlane. Your org holds API keys, routes, and wallet settings.You do not need a production plan to follow this guide. The sandbox is available immediately after signup.
2

Get a Base Sepolia wallet with test USDC

You need an EVM wallet private key and some test USDC on Base Sepolia (eip155:84532).
  1. Generate a new wallet (use Coinbase Wallet, MetaMask, or any EVM wallet that exports a raw private key).
  2. Visit the Circle Faucet, select Base Sepolia, and request test USDC for your wallet address.
  3. Store the private key in an environment variable — never commit it to source control.
export AGENT_PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
Use a dedicated hot wallet with only test USDC. Never reuse a cold-storage key or a key holding real funds.
3

Install the SDK

Install the @meterlane/x402 package. The client subpath is MIT-licensed and open source.
npm install @meterlane/x402
4

Make a paid request

The public demo route at https://gateway.meterlane.app/gateway/demo/demo is a live x402-protected endpoint on Base Sepolia. Use createAgentClient to wrap fetch with automatic payment handling.
import type { Hex } from "viem";
import { createAgentClient } from "@meterlane/x402/client";

const privateKey = process.env.AGENT_PRIVATE_KEY as Hex;

// Defaults to Base Sepolia (eip155:84532) — safe for sandbox
const paidFetch = createAgentClient(privateKey);

const res = await paidFetch(
  "https://gateway.meterlane.app/gateway/demo/demo",
  { method: "GET" }
);

console.log(res.status);          // 200
console.log(await res.text());    // Response body from the demo route
createAgentClient accepts an optional second argument to pin the network:
// Explicit Base Sepolia — same as the default
const paidFetch = createAgentClient(privateKey, "eip155:84532");
Base mainnet (eip155:8453) requires a private mainnet-capable facilitator. The public sandbox facilitator only supports Base Sepolia. Contact the Meterlane team when you are ready for production.
5

Understand the 402 → payment → 200 flow

Here is exactly what happens under the hood when you call paidFetch:
  1. First request — your client sends a plain GET. The gateway has no payment yet, so it returns HTTP 402 Payment Required with an X-Payment-Requirements header describing the USDC price, network, and facilitator address.
  2. Payment signingcreateAgentClient reads the requirements, constructs an ERC-3009 transferWithAuthorization signed by your private key, and encodes it as the X-PAYMENT header value.
  3. Retry with payment — the client retries the same request, this time including X-PAYMENT.
  4. Verification and proxy — the gateway submits the signed authorization to the x402 facilitator, which settles the USDC transfer on-chain. The gateway then proxies the request to the upstream route and returns HTTP 200.
You can probe the route without a wallet to see the raw 402:
curl -i https://gateway.meterlane.app/gateway/demo/demo
The response will look like this:
HTTP/2 402
x-payment-requirements: {"scheme":"exact","network":"eip155:84532","maxAmountRequired":"1000000","resource":"...","description":"...","mimeType":"application/json","payTo":"0x...","maxTimeoutSeconds":60,"asset":"0x...","extra":{"name":"USDC","decimals":6}}
content-type: application/json

{"error":"Payment required"}

What to do next

Now that you have seen the full payment flow, you can create your own protected routes from the dashboard and point agents at your org’s gateway URL.

Agent Gateway Overview

Create routes, set per-request prices, and manage API keys for your org.

Key Concepts

Understand x402, facilitators, ERC-3009, and how Meterlane routes work.

Stablecoin Corridor

Send USDC to local fiat beneficiaries in BRL, MXN, NGN, KES, or ZAR.

API Reference

Full REST reference for gateway and corridor endpoints.