This is an integration guide for JavaScript + Express + @x402/express + the CDP facilitator. HEVN provides the receiving address. The middleware and facilitator are separate services: HEVN does not validate the x402 header or submit the payer's authorization. The snippet below charges real USDC on Base mainnet; test with a separate Base Sepolia address and network before processing live payments.
1. Copy the receiving address from HEVN
In your HEVN business account, go to Account → Deposit → Crypto → Direct (/account/deposit/crypto?tab=direct). Choose USDC and Base as the blockchain. Copy the deposit address displayed for that pair. Recheck the address and the selection after copying. Do not confuse Base mainnet with Base Sepolia or a deposit address for another chain; if HEVN does not display this combination for your account, ask HEVN before you publish the endpoint.
This public address becomes the x402 payTo value. No HEVN wallet secret is needed in the server.
2. Install Express and the maintained x402 packages
npm init -y
npm pkg set type=module
npm install express @x402/express @x402/evm @coinbase/cdp-sdk
Do not copy old tutorials that use the v1 x402-express package or the X-PAYMENT header. The v2 SDK uses @x402/* packages and the PAYMENT-REQUIRED / PAYMENT-SIGNATURE / PAYMENT-RESPONSE header flow. Lock the versions you test before shipping.
Set the receiver and the credentials for the CDP hosted facilitator in your deployment environment:
export HEVN_BASE_USDC_ADDRESS='0xYourHevnBaseUsdcDepositAddress'
export CDP_API_KEY_ID='your-cdp-key-id'
export CDP_API_KEY_SECRET='your-cdp-key-secret'
The CDP key authenticates facilitator requests; it does not receive the proceeds. In this integration you supply your own HEVN payTo address, so a CDP-managed receiver wallet and CDP_WALLET_SECRET are not needed.
3. Add a payment gate before the route
Save the following as server.mjs, or add these imports and middleware to your existing Express application:
import express from 'express'
import { paymentMiddleware, x402ResourceServer } from '@x402/express'
import { ExactEvmScheme } from '@x402/evm/exact/server'
import { createCdpFacilitatorClient } from '@coinbase/cdp-sdk/x402'
const receiver = process.env.HEVN_BASE_USDC_ADDRESS
if (!/^0x[a-fA-F0-9]{40}$/.test(receiver ?? '')) {
throw new Error('Set the HEVN USDC deposit address for Base')
}
const network = 'eip155:8453'
const server = new x402ResourceServer(createCdpFacilitatorClient())
server.register(network, new ExactEvmScheme())
const app = express()
app.use(
paymentMiddleware(
{
'GET /report': {
accepts: [
{ scheme: 'exact', price: '$0.01', network, payTo: receiver }
],
description: 'One paid report',
mimeType: 'application/json'
}
},
server
)
)
app.get('/health', (_request, response) => response.json({ status: 'ok' }))
app.get('/report', (_request, response) => {
response.json({ report: 'Your paid report goes here' })
})
app.listen(8402, () => console.log('API listening on port 8402'))
The route key includes the method and path. An unrelated route such as /health stays free. Register ExactEvmScheme for Base mainnet and point payTo at the HEVN address. Put the middleware before the paid handler so the resource is gated. The CDP facilitator verifies and settles the authorization; the x402 SDK manages the payment challenge and receipt.
4. Check the unpaid response
node server.mjs
curl -i http://localhost:8402/health
curl -i http://localhost:8402/report
Expect 200 from /health and 402 plus a PAYMENT-REQUIRED header from /report. Inspect the decoded challenge with your x402 client or tooling to confirm that the network is eip155:8453, the asset is USDC, the price is correct, and payTo matches the HEVN address. An unpaid 402 alone does not prove that the facilitator can settle a payment.
5. Complete a small live payment
Use a compatible x402 client with a wallet holding a small amount of mainnet USDC on Base. The client reads the challenge, signs the payment, and retries with PAYMENT-SIGNATURE. A successful response includes PAYMENT-RESPONSE; reconcile the settlement transaction with the incoming HEVN deposit and your own API sale record. Never paste a payer private key into a public browser, frontend bundle, or repository.
Add more priced routes to the middleware map when the first route works. Place expensive computation behind the gate, and make state-changing handlers safe against retries. For the latest library signatures, see the official x402 SDK and the CDP Express reference server. If your stack is Python, use our FastAPI walkthrough.
Withdraw your earnings
Once the paid request has settled and the USDC deposit is available in HEVN, you can keep USDC, convert it where supported, or withdraw using an available HEVN route. Check fees, eligibility, timing, and compliance requirements in your account. x402 collects the payment; HEVN is where you manage and withdraw the received funds.