import { x402Client } from "@x402/core/client"; import { ExactEvmScheme } from "@x402/evm/exact/client"; import { wrapFetchWithPayment, x402HTTPClient } from "@x402/fetch"; import { privateKeyToAccount } from "viem/accounts"; const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`); const client = new x402Client(); client.register("eip155:*", new ExactEvmScheme(signer)); const fetchWithPayment = wrapFetchWithPayment(fetch, client); const responseParser = new x402HTTPClient(client); const response = await fetchWithPayment( "https://apiacre.com/v1/research/sec-filing-signals", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ identifier: "AAPL" }), }, ); if (!response.ok) throw new Error(`API Acre returned ${response.status}`); console.log(await response.json()); console.log(await responseParser.processResponse(response));