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?

1
  • 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. Commented Oct 4, 2016 at 6:50

3 Answers 3

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.

1
  • How to get on outside contract? Commented Aug 29, 2017 at 12:19
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.

1
-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;
3
  • 1
    That is not an event definition or an event emitter. Your answer is confusing. Perhaps you could add further information. Commented Aug 1, 2017 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
    Commented Aug 2, 2017 at 2: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. Commented Jan 13, 2023 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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