x402 is an open standard for internet native payments. It aims to support all networks (both crypto & fiat) and forms of value (stablecoins, tokens, fiat).
app.use(
paymentMiddleware(
{
"GET /weather": {
accepts: [...], // As many networks / schemes as you want to support
description: "Weather data", // what your endpoint does
},
},
),
);
// That's it! See examples/ for full detailsInstallation
# All available reference sdks
npm install @x402/core @x402/evm @x402/svm @x402/axios @x402/fetch @x402/express @x402/hono @x402/next @x402/paywall @x402/extensions
# Minimal Fetch client
npm install @x402/core @x402/evm @x402/svm @x402/fetch
# Minimal express Server
npm install @x402/core @x402/evm @x402/svm @x402/expresspip install x402go get github.com/coinbase/x402/go- Open standard: the x402 protocol will never force reliance on a single party
- HTTP Native: x402 is meant to seamlessly complement the existing HTTP request made by traditional web services, it should not mandate additional requests outside the scope of a typical client / server flow.
- Chain and token agnostic: we welcome contributions that add support for new chains, signing standards, or schemes, so long as they meet our acceptance criteria laid out in CONTRIBUTING.md
- Trust minimizing: all payment schemes must not allow for the facilitator or resource server to move funds, other than in accordance with client intentions
- Easy to use: x402 needs to be 10x better than existing ways to pay on the internet. This means abstracting as many details of crypto as possible away from the client and resource server, and into the facilitator. This means the client/server should not need to think about gas, rpc, etc.
The x402 ecosystem is growing! Check out our ecosystem page to see projects building with x402, including:
- Client-side integrations
- Services and endpoints
- Ecosystem infrastructure and tooling
- Learning and community resources
Want to add your project to the ecosystem? See our demo site README for detailed instructions on how to submit your project.
Roadmap: see ROADMAP.md
resource: Something on the internet. This could be a webpage, file server, RPC service, API, any resource on the internet that accepts HTTP / HTTPS requests.client: An entity wanting to pay for a resource.facilitator: A server that facilitates verification and execution of payments for one or many networks.resource server: An HTTP server that provides an API or other resource for a client.
- Permissionless and secure for clients, servers, and facilitators
- Minimal friction to adopt for both client and resource servers
- Minimal integration for the resource server and client (1 line for the server, 1 function for the client)
- Ability to trade off speed of response for guarantee of payment
- Extensible to different payment flows and networks
See specs/ for full documentation of the x402 standard/
x402 payments typically adhere to the following flow, but servers have a lot of flexibility. See advanced folders in examples/.

The following outlines the flow of a payment using the x402 protocol. Note that steps (1) and (2) are optional if the client already knows the payment details accepted for a resource.
-
Clientmakes an HTTP request to aresource server. -
Resource serverresponds with a402 Payment Requiredstatus and aPaymentRequiredb64 object return as aPAYMENT-REQUIREDheader. -
Clientselects one of thePaymentRequirementsreturned by the server response and creates aPaymentPayloadbased on thescheme&networkof thePaymentRequirementsthey have selected. -
Clientsends the HTTP request with thePAYMENT-SIGNATUREheader containing thePaymentPayloadto the resource server. -
Resource serververifies thePaymentPayloadis valid either via local verification or by POSTing thePaymentPayloadandPaymentRequirementsto the/verifyendpoint of afacilitator. -
Facilitatorperforms verification of the object based on theschemeandnetworkof thePaymentPayloadand returns aVerification Response. -
If the
Verification Responseis valid, the resource server performs the work to fulfill the request. If theVerification Responseis invalid, the resource server returns a402 Payment Requiredstatus and aPayment Required ResponseJSON object in the response body. -
Resource servereither settles the payment by interacting with a blockchain directly, or by POSTing thePayment PayloadandPayment PaymentRequirementsto the/settleendpoint of afacilitator server. -
Facilitator serversubmits the payment to the blockchain based on theschemeandnetworkof thePayment Payload. -
Facilitator serverwaits for the payment to be confirmed on the blockchain. -
Facilitator serverreturns aPayment Execution Responseto the resource server. -
Resource serverreturns a200 OKresponse to theClientwith the resource they requested as the body of the HTTP response, and aPAYMENT-RESPONSEheader containing theSettlement Responseas Base64 encoded JSON if the payment was executed successfully.
A scheme is a logical way of moving money.
Blockchains allow for a large number of flexible ways to move money. To help facilitate an expanding number of payment use cases, the x402 protocol is extensible to different ways of settling payments via its scheme field.
Each payment scheme may have different operational functionality depending on what actions are necessary to fulfill the payment.
For example exact, the first scheme shipping as part of the protocol, would have different behavior than upto. exact transfers a specific amount (ex: pay $1 to read an article), while a theoretical upto would transfer up to an amount, based on the resources consumed during a request (ex: generating tokens from an LLM).
See specs/schemes for more details on schemes, and see specs/schemes/exact/scheme_exact_evm.md to see the first proposed scheme for exact payment on EVM chains.
Because a scheme is a logical way of moving money, the way a scheme is implemented can be different for different blockchains. (ex: the way you need to implement exact on Ethereum is very different from the way you need to implement exact on Solana).
Clients and facilitators must explicitly support different (scheme, network) pairs in order to be able to create proper payloads and verify / settle payments.