7

For example, the contract saves the address when token created but after that token holder could send token or all tokens to another wallet.

Is it possible to find all wallet addresses of token holders which were created by my contract?

eth
  • 85,679
  • 53
  • 285
  • 406
eugenn
  • 255
  • 3
  • 6
  • very cool.. Any example of 'IDS IN ARRAY' along with get function to see them?? I'm not so familiar with mapping can't really get my head around it. – user3252381 Oct 04 '16 at 06:50

3 Answers3

6

All token transfers are performed by calling methods on your contract - so your contract can track balances and accounts in any way it wishes. If you're using the default arrangement of using a Solidity mapping, you will also need to keep a separate list of known account IDs in an array, so you can iterate over them.

Nick Johnson
  • 8,144
  • 1
  • 28
  • 35
3

I have created a standalone open source tool which does the same.

  • Take a token contract address

  • Iterate over all ERC-20 Transfer events for token using eth_getLogs JSON-RPC API

  • Build a local database of these events

  • Allow you to use SQL to query any account balance on any point of time (block num) - note that some balances may have become zero

You can find the command line application how to build the database here

The core Python logic is here.

There are some quirks here and there: for example detecting mint / creation event for some tokens is not straightforward. Thus, you will may negative balance on the account receiving initial total supply if you rely on Transfer event only.

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127
  • Wondering if this still works as I see docs page is giving 404 now, https://docs.tokenmarket.net/erc-20-holders.html ? – Blissful Apr 20 '22 at 22:06
-1

You can watch the event as it happens within an app or within the token contract itself use:

mapping (uint => mapping (address => uint)) mappedAccounts;
  • 1
    That is not an event definition or an event emitter. Your answer is confusing. Perhaps you could add further information. – Thomas Clowes Aug 01 '17 at 13:49
  • I think he intended some kind of inverted index like mapping (address => uint) and then mapping (uint => address) to track addresses, like Nick Johnson said. – Ismael Aug 02 '17 at 02:31
  • I know this is ancient but I'm returning from a long battle with illness and coming back to life again! My response was rushed and has two suggestions, therefore unclear. 'Waching the event' is what @Mikko suggested. I added 'or' add a mapping in the 'contract itself' which could be looped through to discover all addresses. Please consider removing downvote. – Jeff Anthony Jan 13 '23 at 11:17