/** * Funding the reserve. The SDK never holds the depositor's key: `depositTx` * returns two unsigned transactions, and you send them from your own wallet. * * node --env-file=.env fund.js 25.00 */ import type { UnsignedTx, Wallet } from "px402"; import { loadConfig } from "./config.js"; import { seedFromEnv } from "./seed.js"; import { recoverWallet } from "./wallet.js"; /** What to send, in order: an ERC-20 approve to the reserve, then the deposit. */ export function depositPlan(wallet: Wallet, usdcAmount: string, rpcUrl: string): readonly UnsignedTx[] { const { reserveAddr, usdc, amountBaseUnits, approve, deposit } = wallet.depositTx(usdcAmount); console.log(`deposit ${usdc} USDC (${amountBaseUnits.toString()} base units) into reserve ${reserveAddr}`); // The same two calls with Foundry, signed by your depositor key. Without // --rpc-url, cast sends to http://localhost:8545. const signer = `--account depositor --rpc-url ${rpcUrl}`; console.log(`cast send ${approve.to} "approve(address,uint256)" ${deposit.to} ${amountBaseUnits.toString()} ${signer}`); console.log(`cast send ${deposit.to} "deposit(address,uint256)" ${reserveAddr} ${amountBaseUnits.toString()} ${signer}`); return [approve, deposit]; } async function main(): Promise { const cfg = loadConfig(); // recover, not open: a refill deposits to a seed that has withdrawn before, // and px402.open refuses one. Building a deposit needs no receipts. const wallet = await recoverWallet(seedFromEnv("PX402_SEED"), cfg, []); // Each is { to, data, value: "0x0", chainId }: hand them to any wallet library. // Sent through the transactions endpoint: cast waits there for each receipt. console.log(JSON.stringify(depositPlan(wallet, process.argv[2] ?? "25.00", cfg.txRpcUrl), null, 2)); } if (process.argv[1]?.endsWith("fund.js") === true) { await main(); }