Skip to content

Token Operations

OxGasClient includes helpers for reading balances and sending ERC-20 tokens without needing to encode ABI calls yourself.

Returns the ETH (or native coin) balance of the smart account as a bigint in wei.

const balanceWei = await client.getNativeBalance();
console.log('Balance:', balanceWei); // e.g. 1000000000000000000n (1 ETH)
const token = await client.getTokenBalance('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'); // USDC
console.log('Balance:', token.balance); // "10.5" (human-readable)
console.log('Symbol:', token.symbol); // "USDC"
console.log('Name:', token.name); // "USD Coin"
console.log('Decimals:', token.decimals); // 6
console.log('Raw:', token.rawBalance); // 10500000n

The return value is always human-readable for display. Use rawBalance when you need the exact on-chain value.

const response = await client.transferToken({
tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
to: '0xRecipientAddress',
amount: '10', // Human-readable — "10 USDC"
});
const receipt = await response.wait();

The amount is in human units. The SDK reads the token’s decimals from the contract and converts it automatically. If you already know the decimals, pass them to skip the extra RPC call:

await client.transferToken({
tokenAddress: '0x...',
to: '0x...',
amount: '100',
decimals: 6, // Skip the decimals lookup
});
FieldTypeRequiredDescription
tokenAddress0x${string}YesThe ERC-20 contract address.
to0x${string}YesRecipient address.
amountstringYesAmount in human-readable units (e.g. "10.5").
decimalsnumberNoToken decimals. If omitted, fetched from the contract.

getTokenBalance() and getNativeBalance() use the smart account address if one has been set up, or the EOA address otherwise. This ensures you’re always reading the balance of the address that will be sending transactions.