Bitcoin Forum
June 25, 2024, 02:04:36 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Newbie Question about crypto wallet development  (Read 60 times)
themo7sn (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
June 18, 2023, 03:42:16 PM
 #1

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
Stalker22
Legendary
*
Offline Offline

Activity: 1540
Merit: 1367



View Profile
June 18, 2023, 04:56:55 PM
 #2

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.

█████████████████████████
██
█████▀▀███████▀▀███████
█████▀░░▄███████▄░░▀█████
██▀░░██████▀░▀████░░▀██
██▀░░▀▀▀████████████░░▀██
██░░█▄████▀▀███▀█████░░██
██░░███▄▄███████▀▀███░░██
██░░█████████████████░░██
██▄░░████▄▄██████▄▄█░░▄██
██▄░░██████▄░░████░░▄██
█████▄░░▀███▌░░▐▀░░▄█████
███████▄▄███████▄▄███████
█████████████████████████
.
.ROOBET 2.0..██████.IIIIIFASTER & SLEEKER.██████.
|

█▄█
▀█▀
████▄▄██████▄▄████
█▄███▀█░░█████░░█▀███▄█
▀█▄▄░▐█████████▌▄▄█▀
██▄▄█████████▄▄████▌
██████▄▄████████
█▀▀████████████████
██████
█████████████
██
█▀▀██████████████
▀▀▀███████████▀▀▀▀
|.
    PLAY NOW    
vv181
Legendary
*
Offline Offline

Activity: 1932
Merit: 1273


View Profile
June 19, 2023, 01:14:40 PM
 #3

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!