fetch wrapper that automatically handles 402 Payment Required responses with USDâ‚®.
See a full working demo at github.com/SemanticPay/x402-usdt0-demo
Install
Create a wallet
Create aWalletAccountEvm pointed at the chain you want to pay on. The account derives keys locally from your seed phrase.
Register with x402
WalletAccountEvm already satisfies the signer interface that x402 expects.
fetchWithPayment now intercepts any 402 Payment Required response, signs an EIP-3009 transferWithAuthorization using your WDK wallet, and retries the request with the payment header attached.
Make a paid request
- Initial request returns
402with aPAYMENT-REQUIREDheader - Client parses the payment requirements (amount, token, network, recipient)
- Client signs an EIP-3009 authorization with your WDK wallet
- Client retries the request with the
PAYMENT-SIGNATUREheader - The facilitator settles the payment on-chain and the server returns the resource
Full example
Environment variables
Checking your balance
Before making paid requests, verify your wallet has USDT0 on the target chain:1000000 equals 1.00 USDâ‚®.
Using Axios instead of fetch
What happens under the hood
x402 uses EIP-3009 (transferWithAuthorization) for payment settlement. When your WDK wallet signs a payment, it creates an off-chain authorization that allows the facilitator to transfer a specific amount of USDT0 from your address to the seller’s address. The facilitator then submits this authorization on-chain in a single transaction.
Because Plasma and Stable both support EIP-3009 natively on their USDT0 contracts, the facilitator can settle payments without any gas cost to the buyer. The buyer only pays the exact amount specified in the payment requirements.