Guides
TypeScript client
Full activation flow with the x402 TypeScript SDK.
npm install @x402/core @x402/evm @x402/axios axios viemComplete example
import { x402Client } from "@x402/core/client";
import { UptoEvmScheme } from "@x402/evm/upto/client";
import { wrapAxiosWithPayment } from "@x402/axios";
import { privateKeyToAccount } from "viem/accounts";
import axios from "axios";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
// upto scheme = authorize max, settle on delivery
const client = new x402Client();
client.register("eip155:8453", new UptoEvmScheme(account));
const api = wrapAxiosWithPayment(
axios.create({ baseURL: "https://api.sms-x402.xyz" }),
client,
);
// 1. order — payment handled automatically (402 → sign → retry)
const order = await api.post("/v1/numbers", { service: "tg", country: 16 });
const { id, accessToken, number } = order.data;
console.log("number:", number);
// 2. use the number in the target service, then poll
for (;;) {
await new Promise((r) => setTimeout(r, 7000));
const res = await api.get(`/v1/numbers/${id}`, {
headers: { Authorization: `Bearer ${accessToken}` },
});
if (res.data.status === "completed") {
console.log("SMS code:", res.data.code);
break;
}
if (res.data.status !== "waiting_code") {
throw new Error(`activation ended: ${res.data.status}`);
}
}Cancel (costs $0)
await api.post(`/v1/numbers/${id}/cancel`, null, {
headers: { Authorization: `Bearer ${accessToken}` },
});Notes
- Status/cancel/retry calls are not x402-paid — they use the
accessToken. Call them with the payment-wrapped client or plain axios; both work. - The
uptoscheme needs a client that supports it (@x402/evm/upto/client). Your maximum authorization equals the quoted price; you are charged exactly the quoted price on delivery, or nothing at all.