fetch integration.
Full example on GitHub
The complete, runnable version of this guide —
examples/x402/exact/client.ts.Prerequisites
- A Sui wallet secret key with a stablecoin balance (use testnet to try it for free)
- Node.js 24+ (or any runtime with WebCrypto and
fetch) - An x402-protected endpoint to call — see Quickstart for sellers
1. Install dependencies
2. Build a signer
AClientSuiSigner is the agent’s wallet — an address and a function that signs transaction bytes. Build one from a Sui Ed25519Keypair:
client.ts
3. Register the Sui scheme and wrap fetch
RegisterExactSuiScheme for the network you pay on, then wrap fetch so payments are handled transparently:
client.ts
4. Make the request
Call the protected endpoint as you normally would. When the server returns402, the wrapped fetch signs the payment and retries automatically:
client.ts
5. Read the payment receipt
The settlement result comes back in the response headers. Usex402HTTPClient to read the transaction digest and link to an explorer:
client.ts
On mainnet, link to
https://suivision.xyz/txblock/<digest> instead. Register "sui:mainnet" on the client to pay on mainnet.Next steps
Supported networks
Networks and tokens you can pay with.
Pay across chains
Use the same Sui wallet to pay services on other chains.