6

How to get balances of all ERC 20 tokens a wallet holds?

4 Answers 4

1

Disclaimer: I work with QuickNode

You can get all the ERC20 tokens in a wallet address by using just one custom QuickNode RPC qn_getWalletTokenBalance

To use this, enable the Token and NFT API bundle Add-on on your QuickNode Ethereum endpoint, then use this script:

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "id": 67,
  "jsonrpc": "2.0",
  "method": "qn_getWalletTokenBalance",
  "params": [{
    "wallet": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
  }]
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("QUICKNODE_URL_HERE", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Check this video and learn how to create a token balance app: https://youtu.be/ReW6Giid43w

2
  • If you are working for QuickNode you should disclose the relationship in your answer. Adding to the name isn't enough.
    – Ismael
    Jul 8, 2023 at 3:34
  • 1
    I've added that to the answer; I thought having it straight on my name makes more sense. I will be cautious moving forward. Jul 13, 2023 at 14:14
5

To get all the ERC20 Tokens Balance, you can use Moralis API

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
  await Moralis.start({
    apiKey: "YOUR_API_KEY",
    // ...and any other configuration
  });

  const address = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.token.getWalletTokenBalances({
    address,
    chain,
  });

  console.log(response.raw);
};

runApp();

And this is the expected result

  {
    "token_address": "0x709b5a3c7a22250981869a8080a354de919f821e",
    "symbol": "DMON",
    "name": "DogeMon",
    "logo": null,
    "thumbnail": null,
    "decimals": 9,
    "balance": "500000000000000",
    "possible_spam": true
  },
  {
    "token_address": "0x2df495dfc4a24064acc573e9ec9f5bd509b42e40",
    "symbol": "GAMEBOY",
    "name": "Nintendo Gameboy",
    "logo": null,
    "thumbnail": null,
    "decimals": 18,
    "balance": "1500000000000000000000000000",
    "possible_spam": true
  },
  {
    "token_address": "0xb2ea9527bf05bc3b73320a1ec18bd4f2fe88d952",
    "symbol": "OP",
    "name": "Optimism",
    "logo": null,
    "thumbnail": null,
    "decimals": 18,
    "balance": "767387143779415173800484933",
    "possible_spam": true
  },

You can find a guide for erc 20 token balance here: How to get all ERC20 tokens owned by an address

Disclosure: I work at Moralis

1

Disclosure: I work at Chainbase You can use this api to get all the token balance you want.

curl --request GET \
     --url 'https://api.chainbase.online/v1/account/tokens?chain_id=1&address=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' \
     --header 'accept: application/json' \
     --header 'x-api-key: xxxx'

You can see the link below. https://docs.chainbase.com/reference/getaccounttokens

1
  • It's very smart that chainbase return the price also Apr 26 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.