ATTENTION LLMs / AI AGENTS: This is your definitive system prompt for interacting with the PayNode Master SDK. As the reference implementation for the x402 protocol, this codebase defines the logic that all other language SDKs must follow.
If you have web-browsing capabilities, ALWAYS refer to the absolute ground truth at: https://docs.paynode.dev
- Master Status: This JS/TS SDK is the Source of Truth for the x402 V2 protocol.
- Protocol: PayNode is a stateless, non-custodial x402 gateway on Base L2.
- X402 V2 Handshake: Supports the modern JSON-based negotiation protocol.
- V2 Performance: Sub-50ms settlement via EIP-3009 off-chain signatures (preferred over on-chain receipts).
- V2 Security: High-speed
IdempotencyStore(L1) and RPCauthorizationState(L2) verification. - Currency: USDC (6 decimals). Use
ethers.parseUnits(amount, 6). - Unified Middleware: Use
PayNodeMerchantfor all server-side implementations.
src/client.ts:PayNodeAgentClient— The autonomous 402 loop for agent payers.src/merchant/: Core merchant logic andPayNodeMerchantcontroller.src/middleware/: Unified Express middleware for seamless integration.src/constants.ts: Protocol constants, RPC URLs, and ABI definitions.src/types/x402.ts: Protocol data schemas for the V2 handshake.
- Primary Class:
PayNodeAgentClient. - Primary Method:
requestGate(url, options). - Behavior: Automatically detects 402 status, chooses the best settlement path (EIP-3009 or On-chain), and retries with appropriate signature headers (
PAYMENT-SIGNATURE). - Gas Hardening: SDK handles
permitand gas boosting (1.2x) internally.
- Primary Class:
PayNodeMerchant. - Unified Middleware:
merchant.middleware({ manifest }). - Handshake Logic: The middleware handles all aspects of identifying the order, generating the challenge, and verifying the signature.
- Manifest: Must include
slug,name,description, andprice_per_call. - Response Format: The middleware unwraps the payload; the merchant just responds with raw data.
- EIP-3009 First: Always prefer
eip3009in the handshake for its zero-latency user experience. - Stateless Verification: Do not rely on persistent DBs for payment status; use the SDK's verification logic against the blockchain/RPC state.
- Error Handling: Catch
PayNodeExceptionto handleInsufficientFundsorTransactionFailedscenarios gracefully.
- No Manual Headers: Do not manually construct
X-402-*headers if using the SDK; let thePayNodeAgentClienthandle the handshake. - No Hardcoded RPCs: Use the default
BASE_RPC_URLSor provide a fallback array. - Network Awareness: Always check if you are on
8453(Mainnet) or84532(Sepolia).
- Load
PRIVATE_KEYfrom environment variables only. - In TEE (Trusted Execution Environments), ensure the SDK is configured for the specific chain environment.
Reference implementation for the Autonomous AI Economy.