Integrations
TypeScript SDK
Plan and buy under a policy and check the receipt, in six lines and one package.
import { TollexClient, TollexTools, PolicyEngine, walletFromEnv } from "@tollex/client";
const net = process.env.TOLLEX_NETWORK;
const policy = new PolicyEngine({ id: "quickstart", agentId: "me", networks: [net], assets: [{ network: net, address: process.env.TOLLEX_USDG, decimals: 6 }], schemes: ["exact"], maxPerRequest: 10_000n, budgets: { daily: 100_000n } });
const tollex = new TollexTools(new TollexClient({ wallet: walletFromEnv(), policy, requireReceipt: true }), process.env.TOLLEX_URL);
const done = await tollex.do({ need: "ETH-USD spot price", input: { pair: "ETH-USD" } });
console.log(JSON.stringify({ result: done.result, charged: String(done.payment.actualAmount), receipt: done.receiptVerification?.valid }));walletFromEnv() reads the key from the file named by TOLLEX_WALLET_KEY_FILE and refuses a file other users can read; the key never appears in code or command lines. resolve() plans without spending; do() buys. Pass approve to the client to confirm each payment with a person or another system after the policy allows it and before anything is signed.
Errors
Failures throw TollexToolsError with a canonical reason: NO_ELIGIBLE_CAPABILITY, POLICY_REJECTED, SETTLEMENT_PENDING, ALREADY_COMPLETED, TRANSPORT_ERROR and the others listed in the API reference. A pending settlement is not a failure: read the operation and never pay twice.
The packages are not on public registries yet. During onboarding you receive tarballs and a wheel; install them from the files, for example
npm install ./tollex-client-0.2.0.tgz.