is there a way to compare the balance of an address at two different times or in general check the balance of an address at a specific time?

I would like to do something like...

uint256 public startTime
address public exampleAddress

function exampleFunction () public constant returns (uint value) {
    if (balanceOf(exampleAddress) < balanceOf_atStartTime(exampleAddress)) {
        returns X;

My preferred input would be a variable like defined above, but an Unix Timestamp or an event would be suitable as well.

Does anyone know a way to do this kind of operation?

Thank you very much in advance

3 Answers 3


Short answer: No you can't get an address's past balance through Solidity. But there is a solution using web3js.

Long answer: You could do something like this to get the balance of an address at a certain time as seen here: Get Balance History of address

with the following code.

let blockNum = web3.eth.blockNumber;
const historicTimestamp = new Date(historicDate).getTime();
while(true) {
  const block = web3.eth.getBlock(blockNum);
  if(block.timestamp < historicTimestamp) break;

//The blockNumber here is your required block number
web3.eth.getBalance(address, blockNumber).then(balance => `Balance at block number is ${balance}`);

Then you could pass it to your smart contract and compare the two balances there or compare in web3 completely.


I don't think this can be done from the smart contract itself.

The best bet you could have is to try using the blocknumber parameter from web3 and estimate the block number as close as possible to your desired timestamp.


You can use Bitquery's Balance update api, which provides balance up to a given time or block.

Here are examples to compare balance at two block levels.


Read more in their docs - https://docs.bitquery.io/docs/examples/balances/balance-api/

Disclosure - I work for Bitquery

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.