@txn-dev/sdk
v0.1.0
Published
TypeScript SDK for txn.dev
Readme
@txn-dev/sdk
TypeScript SDK for txn.dev - payments infrastructure for AI agents.
Install
npm install @txn-dev/sdkUsage
import { Txn } from "@txn-dev/sdk";
const txn = new Txn("txn_live_...");
// Create wallets for your agents
const sender = await txn.wallets.create({ name: "coordinator" });
const worker = await txn.wallets.create({ name: "translator" });
// Pay for completed work
const tx = await txn.pay({
from: sender.id,
to: worker.id,
amount: 0.003,
memo: "translated 340 words en>fr",
});
// List all wallets
const wallets = await txn.wallets.list();
// Get a specific wallet
const wallet = await txn.wallets.get(sender.id);
// Fund a wallet via Stripe
const { checkout_url } = await txn.fund({
wallet_id: sender.id,
amount: 50,
});API Reference
new Txn(apiKey, options?)
Create a client. Options:
baseUrl- Override API URL (default:https://api.txn.dev)
txn.wallets.create({ name, currency?, metadata? })
Create a wallet. Currency defaults to "usd". Supports "usd", "eur", "gbp".
txn.wallets.list()
List all wallets in your organization.
txn.wallets.get(id)
Get a single wallet by ID.
txn.pay({ from, to, amount, memo?, idempotency_key?, metadata? })
Transfer funds between wallets. Settles in ~4ms. Supports sub-cent amounts up to 8 decimal places.
Pass an idempotency_key for safe retries.
txn.fund({ wallet_id, amount })
Generate a Stripe checkout URL to fund a wallet. Amount range: $0.50 - $100,000.
Error Handling
import { Txn, TxnError } from "@txn-dev/sdk";
try {
await txn.pay({ from: "...", to: "...", amount: 100 });
} catch (err) {
if (err instanceof TxnError) {
console.log(err.message); // "Insufficient balance"
console.log(err.status); // 400
}
}License
MIT
