0

Getting a balance for a token from the JSON RPC is simple. This is all I need to get a Tronix balance. The "0xf230b790e05390fc8295f4d3f60332c93bed42e2" part is the contract address for Tronix.

{"id":1,"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0xf230b790e05390fc8295f4d3f60332c93bed42e2","data":"[ADDRESS ABI]"},"latest"]}

But, how do I check what contracts are at an address?

If I do a eth_getTransactionReceipt on a transaction, I can get the contract address, but I need to know what transactions are at the address first. I can't figure this one out... How can I know which transactions have hit an address?

This Ethsplorer API call is exactly what I'm looking for, but I can't figure out how to do this with the JSON RPC: https://api.ethplorer.io/getAddressInfo/0xff71cb760666ab06aa73f34995b42dd4b85ea07b?apiKey=freekey

From doing some reading, a lot of people are saying that I have to scan the entire Blockchain, but I am 90% sure that it is possible to achieve what I am looking for because MyEtherWallet does it. When I connect my Trezor, it makes the above eth_call call and passes the Tronix contract address in to the call, so it knows that there is Tronix at the address, but how does it know this? It's clear that MEW is not scanning the entire Blockchain when I query my wallet, so either they have figured out how to do this with the normal JSON RPC with a call that I'm not understanding properly, or they are making a secret call to some server indexed by addresses.

  • I don't really understand what you want. Do you want to know a contract address? – Florian Castelain Jun 15 '18 at 11:35
  • No. I want to know which tokens are at a given address. See the ethsplorer sample above. – Melbourne Developer Jun 15 '18 at 22:42
2

Technically, ERC-20 tokens are not at the owners addresses. If you have a token, your address is registered in the smart contract of the ERC20 token as a list of [address]: [balance].

To check the register and see your balance, you need the address of the ERC20 token smart contract.

Anyone can make an ERC20 token, and there's no easy decentralized way to list all of them.

You could collect all the addresses listed on https://etherscan.io/tokens and write a script which checked your balance on all of them, but you would have to keep the list updated when new ERC-20 tokens are launched.

Even more ambitiously, you could set up an Ethereum client and parse all contract creations, defining a filter or pattern to identify ERC-20 contracts. But that's very hard to get right.

  • Well that really sucks. I think what I'm hearing is that basically, in order to see which tokens are at a given address, I'd need to download the entire blockchain and set up an indexed database. I'm guessing that's what Ethsplorer have done. You can see an example of what I'm trying to achieve here: api.ethplorer.io/getAddressInfo/… . This call gives you the tokens at a given address. – Melbourne Developer Jun 15 '18 at 22:41
  • But, I'm also a little doubtful that this is completely true because MyEtherWallet can detect which tokens are at an ETH address without scanning through every known token. If what you are saying is true, MyEtherAPI would need to be a complete deviation from the standard JSON RPC. – Melbourne Developer Jun 15 '18 at 22:46
  • I cleared my browsing cache, turned on Fiddler to trace traffic, went in to MEW, plugged in my Trezor, and MEW showed my TRX balance. It made the JSON RPC in the top post to get the TRX balance. How did it know I have TRX? Does it do some secretive indexing by IP address? – Melbourne Developer Jun 15 '18 at 23:19
  • @MelbourneDeveloper In my ether wallet, they scan transaction of the address and detect the linked token. You have no other choice. It's how it works. – Florian Castelain Jun 16 '18 at 6:14
  • 1
    The easy way that I think most do, is to just manually keep a list of the top 100 to 500 tokens by market cap and their contract addresses. Then scan each of those contracts for a given wallet address and show you the result. TRX would obviously be in that list and it would also explain why Etherscan only shows 511 tokens in their token list: etherscan.io/tokens – Svante Jun 18 '18 at 7:54

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.