import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { withPaymentInterceptor } from "x402-axios";
import axios from "axios";
import { seiTestnet } from "viem/chains";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = createWalletClient({
account,
transport: http(),
chain: seiTestnet,
});
const api = withPaymentInterceptor(
axios.create({
baseURL: "https://api.example.com",
timeout: 10000,
}),
client
);
// Use the API client normally - payments are handled automatically
try {
const response = await api.get("/premium-data");
console.log("Premium data:", response.data);
} catch (error) {
console.error("Request failed:", error);
}