import { wrapFetchWithPayment } from "@x402/fetch"; import { x402Client, x402HTTPClient } from "@x402/core/client"; import { ExactEvmScheme } from "@x402/evm/exact/client"; import { privateKeyToAccount } from "viem/accounts"; const privateKey = process.env.EVM_PRIVATE_KEY as `0x${string}`; if (!privateKey) { throw new Error("Set EVM_PRIVATE_KEY to a Base wallet funded with USDC"); } const signer = privateKeyToAccount(privateKey); const client = new x402Client(); client.register("eip155:*", new ExactEvmScheme(signer)); const fetchWithPayment = wrapFetchWithPayment(fetch, client); const httpClient = new x402HTTPClient(client); const response = await fetchWithPayment("https://risk.fetch-sentry.online/wallet-batch?addresses=0x5e8114643966b7fd7d5cfdd8695ffc5c51ff32c0,0xce56d20689d836ec7a728ceb94a15746696c16e6&contract=0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf&chain=base", { method: "GET" }); const data = await response.json(); console.log("Paid response:", JSON.stringify(data, null, 2)); if (response.ok) { const receipt = httpClient.getPaymentSettleResponse((name) => response.headers.get(name)); console.log("Payment settled:", receipt); }