Expand description
§tempo-x402
HTTP 402 Payment Required for the Tempo blockchain.
Implements pay-per-request API monetization using EIP-712 signed authorizations and TIP-20 (ERC-20 compatible) token transfers on the Tempo chain. One header, one on-chain transfer, zero custodial risk.
§How it works
- Client requests a protected endpoint
- Server responds 402 with pricing (token, amount, recipient)
- Client signs an EIP-712
PaymentAuthorization, retries withPAYMENT-SIGNATUREheader - Facilitator atomically verifies the signature, checks balance/allowance/nonce,
and calls
transferFromon-chain - Server returns the content + transaction hash
The facilitator holds no user funds — it only has token approval to call
transferFrom on behalf of clients who explicitly approved it.
§Architecture
Three-party model:
- Client (
client::X402Client) — signs payment authorizations, handles the 402 retry flow - Server (
scheme_server::TempoSchemeServer) — gates endpoints, returns 402 with pricing - Facilitator (
scheme_facilitator::TempoSchemeFacilitator) — verifies signatures and settles on-chain
§Modules
| Module | Purpose |
|---|---|
constants | Chain configuration (ID 42431), token address, well-known addresses |
eip712 | EIP-712 typed-data signing, signature verification, nonce generation |
wallet | WASM-compatible wallet: key generation, EIP-712 signing, payment payloads |
client | Client SDK — handles 402 flow automatically |
scheme | Core trait definitions (scheme::SchemeClient, scheme::SchemeFacilitator, scheme::SchemeServer) |
scheme_server | Server implementation: price parsing and payment requirements |
scheme_facilitator | Facilitator implementation: signature verification and on-chain settlement |
tip20 | On-chain TIP-20 token operations (balance, allowance, transfer, approve) |
nonce_store | Replay protection backends (in-memory and persistent SQLite) |
payment | Payment data structures (payloads, requirements, 402 response body) |
response | Facilitator response types (verify/settle results) |
hmac | HMAC-SHA256 for facilitator request authentication |
security | Constant-time comparison utilities |
network | SSRF protection: private IP detection, DNS validation |
facilitator_client | HTTP client for calling a remote facilitator |
error | Error types for all x402 operations |
§Quick start
Parse a price and generate payment requirements:
use x402::scheme::SchemeServer;
use x402::scheme_server::TempoSchemeServer;
let server = TempoSchemeServer::default();
let (amount, asset) = server.parse_price("$0.001").unwrap();
assert_eq!(amount, "1000"); // 1000 micro-tokens (6 decimals)Generate a wallet and sign a payment:
use x402::wallet::{generate_random_key, WalletSigner};
let key = generate_random_key();
let signer = WalletSigner::new(&key).unwrap();
let address = signer.address();§Workspace crates
| Crate | Purpose |
|---|---|
| tempo-x402 (this crate) | Core library |
tempo-x402-gateway | API gateway + embedded facilitator |
tempo-x402-identity | Agent identity: wallet, faucet, ERC-8004 |
tempo-x402-soul | Autonomous cognition: plans, memory, coding agent |
tempo-x402-node | Self-deploying node with clone orchestration |
§Feature flags
full(default) — all features: async runtime, SQLite nonce store, HTTP clientwasm— WASM-compatible subset: types, EIP-712 signing, wallet (no tokio/rusqlite)demo— includes a demo private key for testing
§Network
- Chain: Tempo Moderato, Chain ID
42431 - Token: pathUSD
0x20c0000000000000000000000000000000000000(6 decimals) - RPC:
https://rpc.moderato.tempo.xyz
Re-exports§
pub use constants::ChainConfig;pub use error::X402Error;pub use scheme_facilitator::TempoSchemeFacilitator;pub use scheme_server::TempoSchemeServer;pub use wallet::build_payment_payload;pub use wallet::generate_random_key;pub use wallet::recover_message_signer;pub use wallet::WalletSigner;
Modules§
- TIP20
- Module containing a contract’s types and functions.
- client
- Client SDK for making paid API requests (handles 402 flow automatically). x402 Client SDK for making paid API requests.
- constants
- Chain configuration, token addresses, and well-known constants. Chain configuration and well-known constants for the Tempo blockchain.
- eip712
- EIP-712 typed-data signing, signature verification, and nonce generation. EIP-712 typed-data signing, signature verification, and nonce generation.
- error
- Error types for x402 operations. Error types for x402 payment operations.
- facilitator_
client - HTTP client for calling a remote facilitator’s
/verify-and-settleendpoint. HTTP client for calling a remote facilitator’s/verify-and-settleendpoint. - hmac
- HMAC-SHA256 utilities for authenticating facilitator requests. HMAC-SHA256 utilities for authenticating facilitator requests.
- network
- Network validation utilities (private IP detection for SSRF protection). Network validation utilities shared across x402 crates.
- nonce_
store - Replay protection via nonce tracking (in-memory and persistent SQLite backends). Replay protection via nonce tracking.
- payment
- Payment data structures exchanged between client, server, and facilitator. Payment data structures exchanged between client, server, and facilitator.
- response
- Facilitator response types returned after verify/settle operations. Facilitator response types for verify and settle operations.
- scheme
- Core trait definitions for the three-party payment model. Core trait definitions for the three-party payment model.
- scheme_
facilitator scheme::SchemeFacilitatorimplementation: signature verification and on-chain settlement.SchemeFacilitatorimplementation for the Tempo blockchain.- scheme_
server scheme::SchemeServerimplementation: price parsing and payment requirements.SchemeServerimplementation for the Tempo blockchain.- security
- Constant-time comparison utilities for timing-attack resistance. Shared security utilities for the x402 payment protocol.
- tip20
- TIP-20 (ERC-20 compatible) on-chain token operations. TIP-20 (ERC-20 compatible) on-chain token operations.
- wallet
- WASM-compatible wallet: key generation, EIP-712 signing, payment payloads. WASM-compatible wallet for x402 payments.