Skip to main content

SDK Sub Accounts

The SDK exposes first-class methods for sub-account operations.

Methods

zendfi.createSubAccount(...)
zendfi.listSubAccounts()
zendfi.getSubAccount(...)
zendfi.getSubAccountBalance(...)
zendfi.mintSubAccountDelegationToken(...)
zendfi.freezeSubAccount(...)
zendfi.drainSubAccount(...)
zendfi.withdrawFromSubAccount(...)
zendfi.withdrawSubAccountToBank(...)
zendfi.createSubAccountAutomationToken(...)
zendfi.revokeSubAccountAutomationToken(...)
zendfi.closeSubAccount(...)

Create

const sub = await zendfi.createSubAccount({
  label: 'user_paschal_001',
  spend_limit_usdc: 500,
  access_mode: 'delegated',
  yield_enabled: false,
});

List and Inspect

const subaccounts = await zendfi.listSubAccounts();
const sub = await zendfi.getSubAccount(subaccounts[0].id);
const balance = await zendfi.getSubAccountBalance(sub.id);

Mint Delegation Token

const token = await zendfi.mintSubAccountDelegationToken(sub.id, {
  scope: 'withdraw_only',
  spend_limit_usdc: 50,
  expires_in_seconds: 900,
  whitelist: ['7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU'],
  single_use: true,
});

Freeze

await zendfi.freezeSubAccount(sub.id, { reason: 'fraud-review' });

Drain to Merchant Wallet

await zendfi.drainSubAccount(sub.id, {
  token: 'Usdc',
  amount: 10,
  mode: 'live',
  passkey_signature,
});

Withdraw to External Address

await zendfi.withdrawFromSubAccount(sub.id, {
  to_address: '7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU',
  amount: 5,
  token: 'Usdc',
  mode: 'live',
  delegation_token: token.delegation_token,
  passkey_signature,
});

Withdraw to Bank (One-Shot)

await zendfi.withdrawSubAccountToBank(sub.id, {
  amount_usdc: 25,
  bank_id: '9PSB7A2A2LJZ3H6Q4G8XJ6A4',
  account_number: '0123456789',
  mode: 'live',
  automation_token: 'saatk_xxxxx',
  delegation_token: token.delegation_token,
  passkey_signature,
});
This method mirrors split bank-withdraw proxy-email OTP automation, so no manual OTP entry is required in your integration. automation_token and delegation_token are mutually exclusive.

Mint Automation Token (Session Auth)

const automation = await zendfi.createSubAccountAutomationToken({
  sub_account_id: sub.id,
  ttl_seconds: 3600,
  max_uses: 25,
  total_limit_usdc: 500,
  per_tx_limit_usdc: 50,
  allowed_bank_ids: ['9PSB7A2A2LJZ3H6Q4G8XJ6A4'],
  allowed_account_numbers: ['0123456789'],
  mode: 'live',
});

Revoke Automation Token

await zendfi.revokeSubAccountAutomationToken(automation.token_id);

Close

await zendfi.closeSubAccount(sub.id);

Passkey Signature Shape

type PasskeySignaturePayload = {
  credential_id: string;
  authenticator_data: number[];
  signature: number[];
  client_data_json: number[];
};
Use this payload for sensitive transfer methods (drainSubAccount, withdrawFromSubAccount, withdrawSubAccountToBank).