An example client that uses x402-reqwest to pay for HTTP requests using the exact x402 payment scheme.
The "exact" scheme transfers the precise token amount required by the server — no permit signatures, no approval flows. This example registers exact scheme clients for both EVM and Solana chains across both V1 and V2 protocol versions.
This small demo shows how to configure a reqwest client to:
- Interact with x402-protected endpoints using the
exactscheme - Support multiple chains (EVM and Solana)
- Work with both V1 and V2 protocol versions
On startup, this example:
- Reads your private keys from env variables
EVM_PRIVATE_KEYandSOLANA_PRIVATE_KEY - Builds a
reqwestclient usingreqwest-middlewareandx402-reqwest - Registers
exactscheme clients (V1Eip155ExactClient,V2Eip155ExactClient,V1SolanaExactClient,V2SolanaExactClient) - Sends a request to a protected endpoint
If the server responds with a 402 Payment Required, the client:
- Parses the server's requirements (supports both V1 and V2 protocols)
- Selects a supported token (e.g. USDC on Base Sepolia or Solana)
- Signs a
TransferWithAuthorization(EVM) or SPL token transfer (Solana) for the exact amount requested - Retries with the signed payment attached
The best part? You don't have to worry about any of this.
Just set your token preferences and treat it like any other reqwest HTTP client.
- Private keys with testnet funds (Base Sepolia USDC for EVM, Solana Devnet USDC for Solana)
- Rust + Cargo
EVM_PRIVATE_KEYand/orSOLANA_PRIVATE_KEYset in your environment (or in.envfile, see.env.example)
# 1. Clone the repo and cd into this example folder
# 2. Create `.env` file
cp .env.example .env
# 3. Set your EVM_PRIVATE_KEY and/or SOLANA_PRIVATE_KEY inside `.env`
# 4. Run
cargo runYou should see the request succeed and print the server's response.
This example uses:
x402-reqwestto intercept 402s and attach signed paymentsalloyfor EVM signingdotenvyto load the.envfilex402-rsfor token/network definitions and amount conversion
x402-rs: Common types and facilitator logicx402-axum: Axum server-side middleware to accept paymentsx402-reqwest: The crate this example is showcasing