Token Balances

Get ERC20 tokens from any address

getAllERC20

Retrieve all token balances of the current user or specified address. Returns an array of token objects (asynchronous).

Options:

  • chain(optional): The blockchain to get data from. Valid values listed above. Default value Eth.

  • address (optional): A user address (i.e. 0x1a2b3x...). If specified the user attached to the query is ignored and the address is used instead.

const balances = await Moralis.Web3.getAllERC20();

Without any parameters specified, it defaults to 'Eth' as chain and the current User, but you can also specify the chain and addressin an options object:

const options = { chain: 'bsc', address: "0x..." }
const balances = await Moralis.Web3.getAllERC20(options);

getERC20

Get a specific token balance. Returns a token object (asynchronous).

Options

  • chain(optional): The blockchain to get data from. Valid values listed above. Default value Eth.

  • address (optional): A user address (i.e. 0x1a2b3x...). If specified the user attached to the query is ignored and the address is used instead.

  • symbol (optional): get the balance for the specified symbol only (i.e. LINK). Case sensitive! Returns the first matching result if there are more than one.

  • tokenAddress (optional): get the balance for the contract address. Use this if there are multiple tokens with the exact same symbol.

const linkBalance = await Moralis.Web3.getERC20({chain: 'ropsten', symbol: 'LINK'});

Leave out the symbol to get the native token balance for the given chain.

const ethBalance = await Moralis.Web3.getERC20(); // defaults to ETH
const bnbBalance = await Moralis.Web3.getERC20({ chain: 'bsc' });

Case Sensitivity

The symbol option is case sensitive! While many tokens use all caps there are some symbols where the only difference is the capitalization.

  • Remember to capitalize common symbols like LINK

    • The symbol "link" has zero results

    • There currently 81 results for "LINK"

  • Avoid automatically applying an upper case function to the symbol name

  • Use the tokenAddress parameter instead when the symbol returns the balance for a different version of the token than you're looking for