Overview
This tutorial walks you through building a complete paid API service from scratch using the x402x payment protocol. You will learn how to:- Quickly obtain the seller’s recipient address
- Create a seller server
- Create a buyer client
- Handle the payment flow
Prerequisites
1. Seller recipient address
Go to app.x402x.ai to register and obtain the seller’s wallet (an EIP-7702 address will be automatically generated, see Why EIP-7702).2. Token address
Currently supported token addresses by the WTF Facilitator:- USD1 (BSC):
0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d
3. Install dependencies
- npm
- pnpm
- bun
Build it
1. Create the seller server
- Generic
- Express middleware
- Hono middleware
Create
server.ts, core logic:View full server code (Generic)
View full server code (Generic)
2. Create the buyer client
Createclient.ts, core logic:
View full client code
View full client code