Get token balance as of x Date

Refresh

April 2019

Views

250 time

1

I'm working on a project where I need to validate that a token holder had possession of tokens at a certain date in the past and then after that lookup the token balance as of that date. Is this possible?

Here's a question that asks for something similar but without taking a date parameter.

https://ethereum.stackexchange.com/questions/11710/how-can-i-find-out-the-token-balance-of-some-address

Thank you!

2 answers

0

You won't be able to do this inside the Ethereum VM. At least, not easily or cheaply. You would need to store the history you're interested in inside a separate search/database platform. This is what http://etherscan.io does.

To build your data, use the event/log system. Include an event declaration in your contract:

event TokenBalance(address indexed _address, uint indexed _date, uint _balance);

From here, listen for events on your contract (or you can retrieve the log history) and insert the data into your search system.

0

I think that best thing to do is to reproduce all of the Smart Contract History about a specific person.

You will have to analyse every transfer call to this smart contract that was from or to this address in order to recreate the evolution of his balance.

Smart Contracts that hold tokens are following a protocol called ERC20, meaning that no matter what token it is, it will, (in theory) work the same.

Also transaction have a Timestamp, so if you identify every call that altered a person’s balance, you can also date them and make a true chronological recreation.