When you call Get Wallet Assets , balances are returned in their smallest unit (wei, satoshi, etc.) as strings:
{
"assets" : [
{
"kind" : "Native" ,
"symbol" : "ETH" ,
"balance" : "1500000000000000000" ,
"decimals" : 18 ,
"verified" : true
},
{
"kind" : "Erc20" ,
"contract" : "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" ,
"symbol" : "USDC" ,
"balance" : "1000000" ,
"decimals" : 6 ,
"verified" : true
}
]
}
To display a human-readable balance, divide by 10^decimals. Always use the decimals value from the API response — different tokens use different values (ETH uses 18, USDC uses 6, WBTC uses 8, etc.).
Never use floating point numbers for balance calculations. Use BigInt in TypeScript or Decimal in Python to avoid precision loss.
Converting for display
function formatBalance ( balance : string , decimals : number ) : string {
const raw = BigInt ( balance )
const divisor = 10 n ** BigInt ( decimals )
const wholePart = raw / divisor
const fractionalPart = raw % divisor
const fractionalStr = fractionalPart . toString (). padStart ( decimals , '0' )
const trimmed = fractionalStr . replace ( /0 + $ / , '' )
return trimmed ? ` ${ wholePart } . ${ trimmed } ` : wholePart . toString ()
}
formatBalance ( '1500000000000000000' , 18 ) // "1.5"
formatBalance ( '1000000' , 6 ) // "1"
formatBalance ( '123456789' , 6 ) // "123.456789"
If you’re using a web3 library, formatUnits does the same thing:
import { formatUnits } from 'ethers'
formatUnits ( '1500000000000000000' , 18 ) // "1.5"
import { formatUnits } from 'viem'
formatUnits ( 1500000000000000000 n , 18 ) // "1.5"
Converting back to raw
When sending a transaction, convert user input back to the smallest unit:
function parseBalance ( amount : string , decimals : number ) : string {
const [ whole , fraction = '' ] = amount . split ( '.' )
const paddedFraction = fraction . padEnd ( decimals , '0' ). slice ( 0 , decimals )
return BigInt ( whole + paddedFraction ). toString ()
}
parseBalance ( '0.5' , 18 ) // "500000000000000000"
Get Wallet Assets API reference for retrieving balances
Transfer Asset API reference for transfers