SDK
Examples
Working code recipes for creating pools, managing members, and settling payments.
Runnable TypeScript code recipes using splitPayClient.
Example: Query a Pool & Members
typescript
import { splitPayClient } from "@/lib/contract/splitpay";async function inspectPool(poolId: number) { // Query pool metadata const pool = await splitPayClient.getPool(poolId); if (!pool) { console.error("Pool not found"); return; } console.log(`Pool #${pool.id} Owner:`, pool.owner); // Query member roster const members = await splitPayClient.getPoolMembers(poolId); for (const m of members) { console.log(`Member ${m.address}: ${m.shareBps / 100}% (${m.shareBps} BPS)`); }}Example: Settle a Payment
typescript
import { splitPayClient } from "@/lib/contract/splitpay";async function executeSettlement(payerAddress: string, paymentId: number, signFn: (xdr: string) => Promise<string>) { // 1. Prepare invocation XDR const rawXdr = await splitPayClient.prepareSettlePayment(payerAddress, paymentId); // 2. Sign XDR with wallet (Freighter or Keypair) const signedXdr = await signFn(rawXdr); // 3. Submit and poll for confirmation const { txHash } = await splitPayClient.submitSignedTx(signedXdr); console.log("Settled on-chain! Tx hash:", txHash); // 4. Query resulting distributions const receipts = await splitPayClient.getDistributions(paymentId); console.log("Disbursed to members:", receipts);}