How to get the balances of erc20 and NFTs that a wallet holds at that given moment? I have tried using ethers and web3 but I cant really find a way to get the results I want. Any available solutions?

2 Answers 2


You need all the addresses of both tokens ERC20 and ERC721. You can grab then either manually or following last transfer events envolving the wallet that you want.

With these two functions you can apply a loop to get the id that the wallet owns. You need the address of the NFT.

    const balance = await NFT.balanceOf(walletAddress);

    const getTokensId = async (recipient, index) => {
        try {
            const result = NFT.tokenOfOwnerByIndex(recipient, index);
            return result;
        } catch (error) {
            console.log(error, "the error for getTokensId");

Check out https://docs.alchemy.com/reference/how-to-get-all-nfts-owned-by-an-address#step-4-get-all-nfts-owned-by-an-address

From the example in the code it looks like you may not need all the contract addresses? I'm not sure about it as I've never tried it out.

Hope it helps

  • The use of alchemy is not relevant to the question. It doesn't help in any way to reach the solution.
    – prc
    Jan 30 at 20:22
  • ah gotcha, my bad i saw OP mention having tried ethers and web3 and asked for any other solutions, which is why i thought the alchemy sdk would be alright
    – shankar
    Jan 31 at 1:08

Your Answer

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

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