An API request is a natural unit to price: a report, an image transformation, a data lookup, or an agent tool call. x402 uses the HTTP 402 Payment Required response to tell a client how to pay. A compatible client signs the payment, retries the request, and receives the resource after the payment flow succeeds. HEVN is the receiving destination, not the x402 middleware or facilitator. Use the open-source x402 SDK and a facilitator that supports Base mainnet; the payTo address determines where the USDC is sent.
Choose your integration
| Your project | Guide | SDK and framework |
|---|---|---|
| Python API | Add x402 payments to FastAPI with HEVN | x402[fastapi,evm] and FastAPI |
| JavaScript API | Add x402 payments to an Express API with HEVN | @x402/express, @x402/evm, and Express |
Both guides cover installation, route configuration, a HEVN receiving address, the mainnet facilitator, and the first paid request. You can use the same receiver address in both services if your HEVN account displays it for USDC on Base.
1. Get the receiving address in HEVN
- Sign in to your approved HEVN business account.
- Open Account → Deposit → Crypto → Direct in the HEVN app. The direct-deposit page path is
/account/deposit/crypto?tab=direct. - Select USDC as the asset and Base as the blockchain/network. Do not select Base Sepolia, Ethereum, or another chain.
- Copy the displayed deposit address. Confirm the asset and network shown next to it, and recheck the address before putting it into your deployment configuration.
If HEVN does not display a USDC deposit address for Base on your account, do not substitute an address for another asset or network. Check your account's availability with HEVN first. This is a public receiving address; you do not need to export a HEVN private key or give one to the x402 server.
2. Pick the right network and facilitator
For live USDC on Base, set network to eip155:8453. Base Sepolia (eip155:84532) is a test network: its test tokens cannot be deposited as real USDC into your HEVN Base mainnet address. To test without moving real funds, use a separate testnet receiver and a facilitator that supports Base Sepolia; switch both the network and receiver when you go live.
The x402 Foundation's public facilitator is convenient for testnet development, but do not assume it supports your production Base mainnet flow. Choose a production facilitator that supports your scheme, token, and network; obtain its credentials and verify its supported networks before launch. The examples in the framework guides use the Coinbase Developer Platform (CDP) hosted facilitator as one option. CDP credentials authenticate your server to that facilitator; they do not replace the HEVN deposit address or move the destination of the proceeds to CDP.
3. Protect one route before expanding
Start with a predictable, idempotent GET resource and a fixed small price. Register the EVM exact scheme, configure a route such as GET /report, set price: "$0.01" (Python: price="$0.01"), network: "eip155:8453", and payTo / pay_to to your copied HEVN address. Install the framework middleware before the protected route handler.
An unpaid request should return 402 with a PAYMENT-REQUIRED challenge. A client that supports x402 reads the challenge, signs a payment, and retries with PAYMENT-SIGNATURE. After successful verification and settlement, it receives the resource and a PAYMENT-RESPONSE receipt. Use the official SDK rather than assembling, parsing, or trusting these headers yourself.
Keep expensive work and side effects out of the unpaid path. For a paid operation that cannot safely be repeated, design for retries and idempotency: payment verification does not make an arbitrary handler idempotent. Add logging around route, payment receipt, and invoice or customer identifiers without logging secrets or full signed payment payloads.
4. Reconcile the first payment and withdraw
Before advertising the endpoint, request it without a payment and check for 402. Then make a small real paid request with a compatible client and a funded Base-mainnet wallet. Check the settlement receipt and transaction on Base; confirm the incoming USDC appears in the HEVN account associated with the copied address. A successful HTTP response alone is not your accounting record. Confirm that your HEVN account supports this source of funds and retain the API sale and transaction records for reconciliation.
When the USDC has arrived and is available in HEVN, you can keep it, convert it where supported, or withdraw it using an available HEVN withdrawal route. Withdrawal options, timing, fees, and compliance checks depend on your account and destination; x402 itself does not perform the withdrawal.
Further reading
- Introducing x402 explains the protocol and its use cases.
- APIs That Get Paid shows the original monetization pattern.
- x402 Foundation SDK and production guidance covers current packages, v2 headers, and facilitator choices.
- CDP x402 examples illustrate a hosted facilitator and app-level integrations.