Get all erc20 balance

Hello,

Whats the best way to get all the erc20 on my wallet?
I’m currently fetching all the coingecko erc20 one by one, but I get request timeout because I make too many requests per seconds, if I add a settimeout on each await contract.methods.balanceOf(account[0]).call() it works, but it takes too much time to complete… is it possible to check all my erc20 balance in one batch without having the problem to reach the calls limit?

Thanks

hi @damland,

Here’s one example: https://medium.com/@wbobeirne/get-all-eth-token-balances-for-multiple-addresses-in-a-single-node-call-4d0bcd1e5625

Depending on your use case you could also use the subscribe method rather than doing lots of http calls: https://medium.com/pixelpoint/track-blockchain-transactions-like-a-boss-with-web3-js-c149045ca9bf

I hope it helps !

Traian

Hi @traian.vila,

Thank you very much for that precious package.
I’ve written the following node.js:

const Web3 = require('web3');
const balanceChecker = require('eth-balance-checker/lib/web3');
const API_INFURA_RINKEBY = 'https://rinkeby.infura.io/v3/<my infura key>';

const web3 = new Web3(API_INFURA_RINKEBY);
const addresses = ['0x3dC71a2Ebc72876c373F1b82055b80f413489926'];
const tokens = ['0xFfB24C35993481FC632Fa61E89fC2ccC820a713E', '0x1CB3850DF43fD5ba59eB5Bc11d80b7Aa3Ce802d9', '0x6bF59B4CaA87F267C00583677E6b410618eE4aE2'];

balanceChecker.getAddressesBalances(web3, addresses, tokens).then(balances => {
  console.log(balances); // { "0x123...": { "0x0": "100", ... }, ... }
}); 

Then I get the following error:
(node:55383) UnhandledPromiseRejectionWarning: Error: Returned error: execution reverted
at Object.ErrorResponse (/Users//node_modules/web3-core-helpers/src/errors.js:29:16)
at /Users/nicobuechel/node_modules/web3-core-requestmanager/src/index.js:140:36

The demos given on medium seems to fail as well.

Do you have any idea?

It might be something wrong with that contract, check the contract call failed transaction on etherscan, you might see a more meaningful message about the failure.