Skip to main content

Account

The ctx.account module handles wallet setup and balance management. All methods require a signer.
import { ContextClient } from "@contextwtf/sdk"

const ctx = new ContextClient({
  apiKey: process.env.CONTEXT_API_KEY!,
  signer: { privateKey: process.env.PRIVATE_KEY! as `0x${string}` },
})

Wallet setup

Before trading, your wallet needs two on-chain approvals:
  1. TUSD approval — Allow the Holdings contract to transfer your TUSD
  2. Operator approval — Authorize the Settlement contract to manage your holdings

Check status

const status = await ctx.account.status()

console.log("Address:", status.address)
console.log("ETH balance:", status.ethBalance)
console.log("TUSD allowance:", status.usdcAllowance)
console.log("Operator approved:", status.isOperatorApproved)
console.log("Needs setup:", status.needsApprovals)

Auto-setup

The setup() method handles both approvals in one call. It skips any that are already done:
const result = await ctx.account.setup()

if (result.usdcApprovalTx) {
  console.log("TUSD approved:", result.usdcApprovalTx)
}
if (result.operatorApprovalTx) {
  console.log("Operator approved:", result.operatorApprovalTx)
}
After calling setup(), there may be a short indexer delay before the API recognizes the approval. If your first order returns a “not approved” error, wait a few seconds and retry.

Gasless setup

Approve the operator without paying gas — the transaction is relayed for you:
const result = await ctx.account.gaslessSetup()

console.log("Tx hash:", result.txHash)
console.log("Relayed by:", result.relayer)
Gasless setup only handles operator approval. You still need TUSD approval and a deposit to trade.

Deposits and withdrawals

Deposit TUSD

Move TUSD from your wallet into the Holdings contract for trading:
const txHash = await ctx.account.deposit(100) // deposit 100 TUSD
console.log("Deposited:", txHash)
The SDK waits for the transaction to be confirmed before returning.

Withdraw TUSD

Move TUSD from the Holdings contract back to your wallet:
const txHash = await ctx.account.withdraw(50) // withdraw 50 TUSD
console.log("Withdrawn:", txHash)

Gasless deposit

Deposit TUSD without paying gas using Permit2:
const result = await ctx.account.gaslessDeposit(100) // deposit 100 TUSD

console.log("Tx hash:", result.txHash)
console.log("Amount:", result.amount)

Mint TUSD

Mint TUSD for development:
await ctx.account.mintTestUsdc(1000) // mint 1000 TUSD
The mint endpoint can be called once per day per API key. This only works on Base Sepolia testnet.

Complete sets

Mint or burn complete sets of outcome tokens (YES + NO pairs):

Mint

Lock TUSD to receive both YES and NO tokens:
const txHash = await ctx.account.mintCompleteSets("0xMarketId...", 10)

Burn

Return equal amounts of YES and NO tokens to recover TUSD:
const txHash = await ctx.account.burnCompleteSets("0xMarketId...", 10)

Getting started

For the full setup flow (approve, deposit, and start trading), see the Before you trade guide.