I am building an angular based app with ionicframework. In this app the user shall be able to retrieve his balance of an erc-20 token. Using web3js's web3.eth.getBalance(MY_ADDRESS) i have to retrieve this address and hand it to web3.eth.getBalance(MY_ADDRESS).

Thank you very much for your detailed response!

I think I got a better idea of what an account an its address does. Unfortunately I am not directly included in developing the smart contract code and cannot provide it. I want to display an accounts balance of my token in the app. Thereafter I want to implement a voting system. Currently I plan on sending the public address as identifier, his balance and some information (what he is voting for) to a database.

I am simply not sure what this public address is and if I can be sure the user is going to what to enter if I simply prompt him to enter his "address".

Do you have different addresses for each erc-20 token?

Can one account have different addresses?

Do you need to have an account for each erc-20 token?

Is my general approach correct?

Any feedback appreciated and thanks in advance!

EDIT: I currently am planning to let the user enter a public address.

  • 1
    Could you provide more information regarding this app? For example, where do you expect your app to get the address from? MetaMask or will it be typed by the user?
    – Iulian
    Sep 27, 2018 at 14:54
  • Each ERC20 token is a different contract and get balance on that ERC token contract will give you the balance (in Wei) of that contract instead of your user's external wallet Sep 27, 2018 at 22:26
  • The correct way is to use ERC20 ABI and do token.balanceOf.call(MY_ADDR) Sep 27, 2018 at 22:28

2 Answers 2


@Cristian answered part about what address is and how it is used and I'll try to answer how to get it

Assuming you set up web3 properly, then simple call of web3.eth.accounts[0] will get you the first address (public key) which might be, but not necessarily is, the address you are looking for.

So if your app uses metamask for the wallet, it will get first address from metamask. If you are using hot wallet approach where you keep pub/priv keys of your users somewhere safe on your server, then you should just fetch address of particular user. But since you are doing it from console, you can read from accounts.

  • Thanks for you time! I am not sure if I understand you correctly. From my understanding you suggest iterating over web3.accounts[] and search for the public address MY_ADDR like so: web3.accounts[MY_ADDR]. Is it correct, that by doing so in any ERC-20 token the account I get returned that way does hold the balance? Sep 28, 2018 at 17:10
  • No, that was not what i proposed. Let's try like this. Account on ethereum blockchain is something similar to the account on some server, so it provides the way for the user to interact with blockchain. One of parameters of that account is public address which you need in this case. Number of tokens that account have is written in token contract something like this balance[accountAddress] = 133; So in order to get that balance you will need to call ERC20 balanceOf function on token contract. So you must know the address that user used when he bought tokens, address is kind of like his username Sep 28, 2018 at 18:22
  • In the above example from your question web3.eth.getBalance(MY_ADDRESS), it will return amount of ether account have, not the amount of tokens. Hope it helps. You just need to understand how contract interaction work (ethereum transactions) and what ERC20 token is in order to make this work Sep 28, 2018 at 18:27

To answer part of your question, the public address on the Ethereum blockchain is an 'identifier' of a particular account. Think about the place where you live, let's call it: 1 Street, New York, NYC, USA.

On the blockchain, the address will be something which identifies a particular account. If you go to etherscan you will be able to see many transactions from different addresses.

It's safe to ask your users to input their public address since this is public information. If you are working with smart contracts and solidity, the keyword "address" is used to refer to a special data type. Documentation here

Address: Holds a 20 byte value (size of an Ethereum address)

You don't need an account for each ERC20-Token. Just to give you an example, 0x0000000000000000000000000000000000000000 (which is genesis block of Ethereum) you can navigate to the website and see on the right "token balance" or all tokens / ERC20 tokens that this address has.

One account can't have more than 1 public address.

Regarding your approach, I don't know what is it but looks great so far on the information you have provided. If you could provide more information such as the smart contract code or a generic graph of how you are going to achieve what you want to do, that would make more sense.

  • Thank you very much for your detailed response! I think I got a better idea of what an account an its address does. Unfortunately I am not directly included in developing the smart contract code and cannot provide it. Sep 28, 2018 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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