4

Other than looping through every transaction since the contract was mined is there a way to get every account that has interacted with a contract (or sent a transaction to an address) conveniently using the standard web3 API that will work for all browsers (Mist/Metamask/Parity)?

7

I was facing exactly the same problem and the easiest solution I've found was to use the parity trace function:

web3.trace.filter({"fromBlock": "STARTING_BLOCK_NUMBER", "toAddress": [YOUR_CONTRACT_ADDRESS]}

Remember to start parity in an archive mode to be able to take advantage of the additional storage indexing:

parity --tracing on --pruning archive
  • Okay, but is there a way to do it with the standard API that will also work with Metamask/Mist? – Samuel Barnes Jul 10 '17 at 16:20
  • 1
    Yes, but it's very inefficient as it requires browsing all of the transactions. That's why parity added indexing in tracing mode to speed up the search. – Jakub Wojciechowski Jul 10 '17 at 16:26
  • That is what I feared, would be great to see this functionality added to the general API. – Samuel Barnes Jul 10 '17 at 16:30
  • @SamuelBarnes Jakub have reason with the general Api is really inefficient and you will have alot of problems with the asyncronous functions and the filters functionalities of the api. Try to use it or use other external api like the etherscan.io – Gawey Jul 11 '17 at 12:50
  • @Gawey Centralised APIs are no good, the question asks if there is a way without looping. We understand there isn't. I have found a solution for my usecase which involves altering the contract design but is unfortunately a solution specific to the circumstance of the contract. – Samuel Barnes Jul 11 '17 at 16:04

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.