2

Is there an example js code that uses web3.js to query the Ethereum blockchain to see all the tokens and contracts associated with an Ethereum address? I'm looking to make an ethereum wallet and want to know how to pull in this data.

  • How do I connect to a public ethereum node to make this query?
  • Which web3.js functions are required to pull in what tokens an address holds?
  • Contracts associated with and address?
  • You need to have a list of token contract addresses externally provided to you. The address itself doesn't know what tokens it holds. You need to ask each token contract separately or query Transfer event for the address and try to figure out from there. – Mikko Ohtamaa Apr 20 '17 at 22:05
5

As Mikko said, you can only ask contracts you know about using functions/interface (ABI) you know about, interpreting the answer in way you know about.

So, I don't think it's possible as stated, but ...

It might be possible narrow the search area and scope and produce something useful. For example, ERC20 is a standard interface. Coupled with a list of known ERC20 tokens (presumably manually maintained), it might be possible to query each contract to see if balanceOf(account) is greater than 0.

So, instead of "All contracts in which this address has meaning" which is too general, consider "All known ERC20-compatible contracts in which this address has a balanceOf() greater than 0." Not saying this will be especially efficient but it might move the problem from out of reach to feasible.

Hope it helps.

  • 1
    let me get this straight. so I would need to query every single contract that issued a token and see if my address has a balance of > 0 for one of these tokens? I'm guessing this is how wallets do it by querying every contract known in order to display your token balances? I'm looking for a solution similar to nxt, where each address just lists out all the tokens you own without the need to query every token issuer to check your balance. thanks! – Patoshi パトシ Apr 29 '17 at 16:13
  • I think we've all understood your question as a description of the intricacies taking place out of the users' sight. That is, guidance on how you would build such a thing. – Rob Hitchens - B9lab Apr 29 '17 at 17:19

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.