封咗個經得起實錫嘅 x402 settle 流程做 npm 包
x402-cdp:CDP 做 facilitator、payer 簽 EIP-3009、無須 browser、worker 唔使持私鑰。
全程式化,附真上鏈 proof。
0x3D5d… 1,000,000 → 0 · payTo 0xB7f4… 0 → 1,000,000 · Δ = +1.0 USDC跟住 5 步上鏈,全程式化。核心代碼:
import { createClient } from 'x402-cdp'
const c = createClient({ cdpKeyFile:'./cdp.json', payerFile:'./payer.json',
payTo:'0xB7f4…', amount:1_000_000 })
const r = await c.settle() // r.txHash, r.explorerUrl, r.onChainVerified
最難嘅幾個坑(CDP key 要 Transfer+Receive、Windows
stdin is not a tty、mainnet USDC 個 EIP-712 domain 係 USD Coin 唔係 USDC)
全部封喺入面。睇完整免費教學(ARTICLE.md)。
| 方法 | 點做 |
|---|---|
| A. x402 paywall(agent 自動付) | 買家嘅 agent 向 /download 發請求,收 402 + paymentRequirements(payTo 即上面地址),
用 x402 簽 EIP-3009 付 USDC → 上鏈 settle 解鎖下載。呢個係我哋 SDK 自己 dogfood。
(現階段 testnet 地址,mainnet 版隨收款地址切 mainnet 即啟用) |
| B. USDC 直轉 + email txHash(人手,mainnet 即刻可做) | 買家喺 Base 轉 $49 USDC 去上面地址 →
將 txHash + 你個 email 寄去 logout3login@proton.me → 我查上鏈、回傳簽名
x402-cdp-*.tgz + mainnet config + 30min 支援。 |
數字產品。 testnet 地址只係演示(1.0 Sepolia USDC,無市值); 真錢收款 = 切去你控制嘅 Base mainnet 地址。
| 坑 | 解法 |
|---|---|
CDP key 只 View | /settle 會 403;要 Transfer+Receive |
testnet.base.org DNS 不通 | 用 https://sepolia.base.org |
Windows stdin is not a tty | 命令尾加 </dev/null |
| mainnet USDC EIP-712 domain | 係 USD Coin(usdc 小寫)唔係 USDC;改 usdc/usdcDomain/chainId/network |
v2 payload 多咗 type:'eip3009' | exact-EVM schema 會 break;payload 只係 {signature, authorization} |
| replay | 每個 authorization.nonce fresh random bytes32 |