import axios from "axios";
import { withPaymentInterceptor } from "x402-axios";
import { privateKeyToAccount } from "viem/accounts";
// Create a signer from your private key
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
// Wrap axios with x402 payment interceptor
const api = withPaymentInterceptor(
axios.create({ baseURL: "https://api.snack.money" }),
account as never
);
// Send payment - x402 handles the payment flow automatically
const response = await api.post("/payments/x/pay", {
amount: 0.01,
currency: "USDC",
receiver: "0xmesuthere",
description: "Payment via x402"
});
console.log("Payment successful!", response.data);
// {
// "code": 200,
// "msg": "0.01 USDC sent successfully",
// "data": {
// "txn_id": "...",
// "amount": 0.01,
// "receipt": "https://snack.money/x/0xmesuthere?txn=..."
// }
// }