Python script to fetch all ERC-20 tokens and NFT balances from Ethereum wallet using web3.py

I’m looking for a Python solution that can check all token balances for any Ethereum address. Right now I can only retrieve ETH balance but I want to get every ERC-20 token and NFT that the wallet holds.

What I need is a script that takes an Ethereum address as input and returns the complete portfolio including all tokens and NFTs. I’ve been trying different approaches but keep getting stuck on fetching only the native ETH balance instead of the full token list.

Can someone help me create a comprehensive balance checker that works with web3.py? The output should display all holdings for the given wallet address.

Oh this is interesting! I’ve been working on something similar and hit the same roadblock initially. Have you tried using the web3.py contract interface to call balanceOf directly?

I’m curious how you’re handling token discovery. Do you already have a list of token contract addresses to check, or are you trying to dynamically discover which tokens an address holds? That’s the tricky part - Ethereum doesn’t keep a default “list” of tokens per address.

I’ve been experimenting with scanning transaction logs for Transfer events, but it gets resource intensive. Have you considered using the Graph Protocol to query token transfers? Might be more efficient than iterating through every possible token contract.

What’s your use case? Building a portfolio tracker or something else? Might help us suggest better approaches depending on what you’re doing with the data.

Fetching token balances for ERC-20 tokens and NFTs from an Ethereum wallet can indeed be challenging. As you’ve noted, the blockchain operates differently than one might expect. To reliably obtain all your token balances, you’ll generally start by using Etherscan or Moralis to compile a list of tokens associated with your wallet. For each of these tokens, you will invoke the balanceOf method using web3.py. Regarding NFTs, fetching these might require handling the Transfer events if contracts do not implement the enumerable extension. While it is possible to do this manually, consider leveraging APIs like Alchemy’s token API or CovalentHQ, which can simplify the process significantly.

multicall is def the way 2 go! you can get all the token balances in 1 go instead of making multiple calls, super efficient. just make sure u have that token list ready, i usually grab mine from the coingecko api and then filter it for my specific address. gl!