2

How do I get the count of an erc20 token e.g. KNC of an address via Etherscan API?

Or is there another API that can do that?

thx

1

Such an API would require both the account address you want to query the balance for, as well as the address of the ERC-20 contract itself.

Such a service doesn't appear to be provided by Etherscan, in either their Accounts or Tokens API endpoint.

Instead you could have a look at a service like TokenBalance, which provides the following endpoint for the main network:

https://api.tokenbalance.com/token/$CONTRACT/$ETH_ADDRESS

(Associated GitHub repo, here.)

There are probably other sites providing the same service.

Edit:

As an example, the below call queries the KNC contract (address: 0xdd974d5c2e2928dea5f71b9825b8b646686bd200) for the balance of an address I picked from the list of holding address.

 https://api.tokenbalance.com/token/0xdd974d5c2e2928dea5f71b9825b8b646686bd200/0x3eb01b3391ea15ce752d01cf3d3f09dec596f650

The output, in JSON format, is:

{
  "name": "Kyber Network Crystal",
  "wallet": "0x3eb01b3391ea15ce752d01cf3d3f09dec596f650",
  "symbol": "KNC",
  "balance": "81584601.83886412108548039",
  "eth_balance": "95011.193424973798190977",
  "decimals": 18,
  "block": 4651327
}
  • That tokenbalance API does not work for me – Ini Jan 5 '18 at 13:14
  • It works for me if I query the KNC token. I've edited the answer with this as an example. What error are you seeing? – Richard Horrocks Jan 6 '18 at 17:22
  • do you know how to get the same information using JSON-RPC? thanks – Diego Feb 23 '18 at 16:42

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.