Token Operations

Read balances, check allowances, and approve token spending using the client.erc20 module.

Methods

Method
Description
Signer

getBalance(token, owner?)

Get token balance

No

getAllowance(token, owner, spender)

Get spending allowance

No

getDecimals(token)

Get token decimals (cached)

No

getSymbol(token)

Get token symbol

No

approve(token, spender, amount)

Approve token spending

Yes

ensureAllowance(token, spender, amount)

Approve only if current allowance is insufficient

Yes

transfer(token, to, amount)

Transfer tokens to address

Yes

encodeApprove(token, spender, amount)

Encode approval for external wallet

No

Usage

Read Balance and Allowance

import { ethers } from 'ethers';
import { ThetanutsClient } from '@thetanuts-finance/thetanuts-client';

const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
const client = new ThetanutsClient({ chainId: 8453, provider });

const usdcAddress = client.chainConfig.tokens.USDC.address;
const userAddress = '0xYourAddress';

// Get token balance
const balance = await client.erc20.getBalance(usdcAddress, userAddress);
console.log(`Balance: ${ethers.formatUnits(balance, 6)} USDC`);

// Get token decimals (cached after first call)
const decimals = await client.erc20.getDecimals(usdcAddress);
console.log(`Decimals: ${decimals}`); // 6

// Check allowance before a fill or RFQ
const spender = client.chainConfig.contracts.optionBook;
const allowance = await client.erc20.getAllowance(usdcAddress, userAddress, spender);
console.log(`Allowance: ${ethers.formatUnits(allowance, 6)} USDC`);

Approve Spending

ensureAllowance() checks the current allowance first and only submits an approval transaction if needed. This is the preferred pattern before fillOrder() or requestForQuotation().

Transfer Tokens

Encode Approval for External Wallets

Use encodeApprove() when you need to submit the approval through viem, wagmi, a Safe multisig, or another external wallet rather than the built-in ethers signer.

Token Addresses (Base Mainnet)

All addresses are available from client.chainConfig — no hardcoding needed.

Decimal Reference

Token
Decimals
Example

USDC

6

1_000000n = 1 USDC

WETH

18

1_000000000000000000n = 1 WETH

cbBTC

8

1_00000000n = 1 cbBTC

Use client.utils for safe conversions:

See Also

Last updated