This example demonstrates how to use the UPS SDK in a plain Node.js environment to simulate a complete payment flow between two parties.
- Node.js >= 18
- pnpm
-
Install dependencies (from root):
pnpm install
-
Configure environment: Copy
.env.exampleto.envand update values.cp .env.example .env
Required Configuration:
UPS_API_URL: URL of the UPS API (must include/api/v1suffix, e.g.,http://localhost:8080/api/v1)NETWORK_ID: Chain ID of the network (must match the running chain, e.g.,eip155:737998412for Tau Testnet)BLOCKCHAIN_PRIVATE_KEY: Admin private key (0x-prefixed) used to fund the buyer's account with tokens.TOKEN_ADDRESS: Address of the ERC-20 payment token.
pnpm startThis will automatically:
- Initialize the SDK.
- Create a Buyer Smart Account (simulating a user).
- Create a Merchant Smart Account.
- Fund the Buyer with tokens (using the Admin key).
- Execute a Payment from the Buyer to the Merchant using the
x402protocol.
=== Creating Buyer Account ===
Buyer Wallet: 0x...
Buyer Smart Account: 0x...
=== Creating Merchant Account ===
Merchant Wallet: 0x...
Merchant Smart Account: 0x...
=== Funding Buyer ===
Funding TX Hash: 0x...
Funding confirmed
Buyer Balance: 100000000
=== Payment Flow ===
Payment Result Object: { ... }
Payment success: true
Payment TX Hash: 0x...
Note: Ensure your local backend services and blockchain node (or testnet connection) are running and accessible.