How to get ERC20 token balance of any input address

Hello pls i need help on getting erc20 token balance of any address inputted from the frontend of an HTML


If you need that for only a specific ERC20 token balance, then you can use Moralis.Web3API.account.getTokenBalances and specify that address in options:

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

and after that to filter for your specific ERC20 token address in the output.

Only in the case that you want that output only for a specific ERC20 token, you could also use Moralis.executeFunction and query directly the blockchain:, but this option is a little more complicated compared to the previous option.

1 Like

hello @cryptokid i tried to get the balance of a token with the code below

// Application id from


//Server url from

Moralis.serverURL = '';

const authButton = document.getElementById('btn-auth');

const enableButton = document.getElementById('btn-enable');

const logoutButton = document.getElementById('btn-logout');

const callButton = document.getElementById('btn-call');

const subheader = document.getElementById('subheader');

const resultBox = document.getElementById('result');

const ethbalance= document.getElementById('ethbalance');

let user;

let web3;

let result = '';

const provider = ['walletconnect',






function renderApp() {

  user = Moralis.User.current();

  if (user) { = 'none'; = 'inline-block';

    subheader.innerText = `Welcome ${user.get('ethAddress')}`;

    ethbalance.innerText=`Balance: ${user.get('username')}`;

    if (web3) { = 'inline-block'; = 'none';

    } else { = 'none'; = 'inline-block';


  } else { = 'inline-block'; = 'none'; = 'none';

    subheader.innerText = '';

    ethbalance.innerText = ''; = 'none';


  resultBox.innerText = result;


async function authenticate() {

    if (provider == provider) {

        const user = await Moralis.authenticate({ provider: provider});

         web3 = await Moralis.enable({ provider });



             const user = await Moralis.authenticate();

              web3 = await Moralis.Web3API.enable();





async function userBNB(User){

    // get BSC native balance for a given address

    const optionsBNB = { chain: "eth"};

    const balance = await Moralis.Web3API.account.getNativeBalance(optionsBNB);



async function logout() {

  try {

    await Moralis.User.logOut();

  } catch (error) {

    console.log('logOut failed', error);


  result = '';



async function testCall() {

  try {

    result = await web3.eth.personal.sign('Hello world', user.get('ethAddress'));

  } catch (error) {

    console.log('testCall failed', error);




async function enableWeb3() {

  try {

    web3 = await Moralis.Web3.enable({ provider });

  } catch (error) {

    console.log('testCall failed', error);




authButton.onclick = authenticate;

logoutButton.onclick = logout;

callButton.onclick = testCall;

enableButton.onclick = enableWeb3;


but am receiving errors

Screenshot 2021-11-04 022445

Same a transaction too
pls help

Hi, there is a new syntax that you have to use now, with Moralis.start, you have an example here:

Ohhh okay I will give you feedback soon

I can not get the ERC20 balance (ex: eth)

what you mean by this? eth is not an ERC20 token

oh, my bad, how can get all token (ERC20, ERC721, …) in wallet account using moralis?