x402 Payment Gateway
SDK source (GitHub): https://github.com/tangle-network/blueprint/tree/main/crates/x402
x402 is an optional, off-chain payment ingress path for job execution. It exposes HTTP endpoints that require a valid
x402 payment (typically stablecoins on an EVM chain) and then injects a JobCall into the Blueprint Runner after the
payment is verified and settled by an x402 facilitator.
This is useful when you want a service to accept payments from clients on EVM chains without requiring the client to submit on-chain Tangle transactions for each job.
How It Fits In the Runner
X402Gateway runs as a BackgroundService and X402Producer is the paired producer that converts verified payments
into JobCalls.
Quick start (from the crate docs):
Each x402-originated JobCall includes metadata for correlation and accounting:
X-X402-ORIGINandX-X402-QUOTE-DIGESTX-X402-PAYMENT-NETWORKandX-X402-PAYMENT-TOKENX-TANGLE-SERVICE-IDandX-TANGLE-CALL-ID(synthetic, for correlation)
Enabling It (Blueprint SDK)
If you are using blueprint-sdk, enable the feature flag:
[dependencies]
blueprint-sdk = { version = "*", features = ["x402"] }You can also depend on blueprint-x402 directly.
Configuration (TOML)
The operator configures:
- where the gateway listens (
bind_address) - which facilitator to use (
facilitator_url) - which tokens and chains are accepted (
accepted_tokens) - conversion rates from wei-denominated job prices into token amounts (
rate_per_native_unit, plus optionalmarkup_bps)
Job Pricing Input
The x402 gateway needs a per-job price map in wei:
- key:
(service_id, job_index) - value:
price_wei
This is the same shape as the pricing engine job pricing config, and it is intentionally explicit. If a job is not in
the map, the gateway returns 404 for that job.
HTTP Endpoints
The gateway exposes:
GET /x402/health: returnsok.GET /x402/jobs/{service_id}/{job_index}/price: discovery endpoint that returns the wei price and settlement options (no payment required).POST /x402/jobs/{service_id}/{job_index}: paid job execution. The x402 middleware returns402with payment requirements if no valid payment is provided. After payment settles, the gateway returns202 Acceptedand injects aJobCallinto the runner.
Relationship to RFQ and the Pricing Engine
Tangle’s on-chain RFQ path is submitJobFromQuote. Separately, operators can expose x402 as an off-chain settlement
path.
The pricing engine proto includes optional x402 fields (settlement_options, x402_endpoint) in GetJobPriceResponse.
At time of writing, enabling those fields requires constructing PricingEngineService programmatically with
with_x402_settlement, since the pricing-engine-server binary does not expose x402 flags yet.
Operational Notes
- Keep
facilitator_urlpinned to a trusted HTTPS endpoint. - Keep conversion rates current. Stale
rate_per_native_unitvalues create user-facing price surprises. - Treat the HTTP body as untrusted input and validate it inside the job handler.