Token Operations
OxGasClient includes helpers for reading balances and sending ERC-20 tokens without needing to encode ABI calls yourself.
Get native token balance
Section titled “Get native token balance”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)Get ERC-20 token balance
Section titled “Get ERC-20 token balance”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); // 6console.log('Raw:', token.rawBalance); // 10500000nThe return value is always human-readable for display. Use rawBalance when you need the exact on-chain value.
Transfer ERC-20 tokens
Section titled “Transfer ERC-20 tokens”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});Token transfer parameters
Section titled “Token transfer parameters”| Field | Type | Required | Description |
|---|---|---|---|
tokenAddress | 0x${string} | Yes | The ERC-20 contract address. |
to | 0x${string} | Yes | Recipient address. |
amount | string | Yes | Amount in human-readable units (e.g. "10.5"). |
decimals | number | No | Token decimals. If omitted, fetched from the contract. |
Which address is used?
Section titled “Which address is used?”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.