Author

Topic: Newbie Question about crypto wallet development (Read 78 times)

legendary
Activity: 1932
Merit: 1273
It looks there's no direct way to do that in Web3 or EthersJS
And I don't prefer to use external service like Moralis or BSCScan.com, to save costs and support more chains without limits

Due to how the ERC-20 token standard behaves it does indeed there is no direct way. If we also look at a popular wallet like Metamask, they only keep a handful of listed token contracts, if the token is not listed by them, the user has to add them manually.

Furthermore, you also might find this thorough explanations relevant, How to get all tokens by wallet address:

ERC-20 (and ERC-20-like such as TRC-20, BEP-20, etc.) token balance of each address is stored in the contract of the token.

Blockchain explorers scan each transaction for Transfer() events and if the emitter is a token contract, they update the token balances in their separate DB. The balance of all tokens per each address (from this separate DB) is then displayed as the token balance on the address detail page.

Etherscan and BSCScan currently don't provide an API that would return the token balances per address.

In order to get all ERC-20 token balances of an address, the easiest solution (apart from finding an API that returns the data) is to loop through all token contracts (or just the tokens that you're interested in), and call their balanceOf(address) function.

So as the Stack Overflow answer above, the likely implementation you might want to use is to loop the contracts. Besides, I recommend you take a reference on how MetaMask implements the functionalities.
legendary
Activity: 1526
Merit: 1359
This is about Altcoins. I recommend moving your discussion to the Altcoin Discussion section, as you are more likely to receive a better response there.
newbie
Activity: 5
Merit: 0
I'm a senior developer but newbie in web3 development

I'm looking to build a crypto wallet functionalities into my NodeJS server.

Would like to understand some point related to the tokens

How to get the list of tokens for a coin address with their balances

for example

that address : https://bscscan.com/address/0xe934d2c5be5db0295a4de3177762a9e8c74ae4f4

it has

21311 Cake
0.002 NGM

It looks there's no direct way to do that in Web3 or EthersJS
And I don't prefer to use external service like Moralis or BSCScan.com, to save costs and support more chains without limits
Jump to: