I’m looking for a Python solution that can fetch complete token information from an Ethereum wallet. My current attempts only return ETH balance instead of showing all the ERC-20 tokens and NFTs associated with the address.
What I want to achieve:
- Input: Ethereum wallet address (0x format)
- Output: Complete list of all tokens and NFTs with their balances
I’ve been struggling with this for a while and my code keeps missing the token data. Can someone provide a working example that covers both ERC-20 tokens and NFTs? I’m using web3.py library and need the results displayed through print statements.
Any help with a comprehensive script would be greatly appreciated. Thanks in advance!
To retrieve token balances using web3.py, you first need to import the library and connect to an Ethereum node. For ERC-20 tokens, you can interact with each token contract’s balanceOf function, providing the wallet address as an argument. Given the large number of tokens, consider using external APIs like Etherscan to simplify the process. For NFT balances (ERC-721), you’ll follow a similar approach but with the corresponding contract methods. Keep in mind the rate limits when making multiple requests.
Hey! This is a pretty interesting challenge. I’ve been working on similar stuff and hit the same issues.
Are you querying the blockchain directly with web3.py for token balances? That’s tricky since you need to know which tokens the wallet holds first to check their contract addresses.
Have you tried the Alchemy API or Moralis? They’ve got endpoints that return all tokens in one call. I know you mentioned web3.py specifically, but sometimes the right tool makes all the difference.
When you say your code “keeps missing the token data” - are you getting errors or just empty results? And are you on mainnet or testnet?
For NFTs, you’ll need to scan ERC-721 and ERC-1155 transfer events to find what the wallet owns. That gets complex fast with web3.py from scratch.
What’s your current approach? Scanning transfer events or calling specific contract methods? Sharing some of your existing code (even if it’s broken) would help others give better advice.
etherscan API is a lifesaver! using web3.py for each token can get messy real fast. just a simple request to etherscan’s token balance endpoint can make life easier. totally recommend it!