coinbase / x402
- пятница, 26 сентября 2025 г. в 00:00:03
A payments protocol for the internet. Built on HTTP.
"1 line of code to accept digital dollars. No fee, 2 second settlement, $0.001 minimum payment."
app.use(
// How much you want to charge, and where you want the funds to land
paymentMiddleware("0xYourAddress", { "/your-endpoint": "$0.01" })
);
// That's it! See examples/typescript/servers/express.ts for a complete example. Instruction below for running on base-sepolia.
Payments on the internet are fundamentally flawed. Credit Cards are high friction, hard to accept, have minimum payments that are far too high, and don't fit into the programmatic nature of the internet. It's time for an open, internet-native form of payments. A payment rail that doesn't have high minimums + % based fee. Payments that are amazing for humans and AI agents.
The x402 ecosystem is growing! Check out our ecosystem page to see projects building with x402, including:
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 server
: A server that facilitates verification and execution of on-chain payments.resource server
: An HTTP server that provides an API or other resource for a client.The x402
protocol is a chain agnostic standard for payments on top of HTTP, leverage the existing 402 Payment Required
HTTP status code to indicate that a payment is required for access to the resource.
It specifies:
PaymentRequirements
)X-PAYMENT
that is set by clients paying for resourcesX-PAYMENT
headerfacilitator
)X-PAYMENT-RESPONSE
header that can be used by resource servers to communicate blockchain transactions details to the client in their HTTP responseThe 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.
Client
makes an HTTP request to a resource server
.
Resource server
responds with a 402 Payment Required
status and a Payment Required Response
JSON object in the response body.
Client
selects one of the paymentRequirements
returned by the server response and creates a Payment Payload
based on the scheme
of the paymentRequirements
they have selected.
Client
sends the HTTP request with the X-PAYMENT
header containing the Payment Payload
to the resource server.
Resource server
verifies the Payment Payload
is valid either via local verification or by POSTing the Payment Payload
and Payment Requirements
to the /verify
endpoint of a facilitator server
.
Facilitator server
performs verification of the object based on the scheme
and network
of the Payment Payload
and returns a Verification Response
.
If the Verification Response
is valid, the resource server performs the work to fulfill the request. If the Verification Response
is invalid, the resource server returns a 402 Payment Required
status and a Payment Required Response
JSON object in the response body.
Resource server
either settles the payment by interacting with a blockchain directly, or by POSTing the Payment Payload
and Payment PaymentRequirements
to the /settle
endpoint of a facilitator server
.
Facilitator server
submits the payment to the blockchain based on the scheme
and network
of the Payment Payload
.
Facilitator server
waits for the payment to be confirmed on the blockchain.
Facilitator server
returns a Payment Execution Response
to the resource server.
Resource server
returns a 200 OK
response to the Client
with the resource they requested as the body of the HTTP response, and a X-PAYMENT-RESPONSE
header containing the Settlement Response
as Base64 encoded JSON if the payment was executed successfully.
Payment Required Response
{
// Version of the x402 payment protocol
x402Version: int,
// List of payment requirements that the resource server accepts. A resource server may accept on multiple chains, or in multiple currencies.
accepts: [paymentRequirements]
// Message from the resource server to the client to communicate errors in processing payment
error: string
}
paymentRequirements
{
// Scheme of the payment protocol to use
scheme: string;
// Network of the blockchain to send payment on
network: string;
// Maximum amount required to pay for the resource in atomic units of the asset
maxAmountRequired: uint256 as string;
// URL of resource to pay for
resource: string;
// Description of the resource
description: string;
// MIME type of the resource response
mimeType: string;
// Output schema of the resource response
outputSchema?: object | null;
// Address to pay value to
payTo: string;
// Maximum time in seconds for the resource server to respond
maxTimeoutSeconds: number;
// Address of the EIP-3009 compliant ERC20 contract
asset: string;
// Extra information about the payment details specific to the scheme
// For `exact` scheme on a EVM network, expects extra to contain the records `name` and `version` pertaining to asset
extra: object | null;
}
Payment Payload
(included as the X-PAYMENT
header in base64 encoded json)
{
// Version of the x402 payment protocol
x402Version: number;
// scheme is the scheme value of the accepted `paymentRequirements` the client is using to pay
scheme: string;
// network is the network id of the accepted `paymentRequirements` the client is using to pay
network: string;
// payload is scheme dependent
payload: <scheme dependent>;
}
A facilitator server
is a 3rd party service that can be used by a resource server
to verify and settle payments, without the resource server
needing to have access to a blockchain node or wallet.
POST /verify. Verify a payment with a supported scheme and network:
{
x402Version: number;
paymentHeader: string;
paymentRequirements: paymentRequirements;
}
{
isValid: boolean;
invalidReason: string | null;
}
POST /settle. Settle a payment with a supported scheme and network:
Request body JSON:
{
x402Version: number;
paymentHeader: string;
paymentRequirements: paymentRequirements;
}
Response:
{
// Whether the payment was successful
success: boolean;
// Error message from the facilitator server
error: string | null;
// Transaction hash of the settled payment
txHash: string | null;
// Network id of the blockchain the payment was settled on
networkId: string | null;
}
GET /supported. Get supported payment schemes and networks:
{
kinds: [
{
"scheme": string,
"network": string,
}
]
}
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.
Requirements: Node.js v24 or higher
From examples/typescript
run pnpm install
and pnpm build
to ensure all dependent packages and examples are setup.
Select a server, i.e. express, and cd
into that example. Add your server's ethereum address to get paid to into the .env
file, and then run pnpm dev
in that directory.
Select a client, i.e. axios, and cd
into that example. Add your private key for the account making payments into the .env
file, and then run pnpm dev
in that directory.
You should see activities in the client terminal, which will display a weather report.
cd typescript
pnpm install
pnpm test
This will run the unit tests for the x402 packages.