How to get address balance if you know the block number? In solidity you can call address.balance, but without specifying particular block. Is there a way to do this in solidity or only py/js?


If I understand correctly, you want to get the balance of a particular address at a given block number, which you can't do in Solidity. If this were the case, it would make any non-full-sync mode impossible as verifying blocks would require access to the state at any arbitrary block in the past, which geth --fast wouldn't be able to do. Verifying blocks on full nodes would also be a lot more intensive due to the arbitrary block state access.


As @flygoing points out, you cannot get a historical balance in Solidity, but you can get that value off-chain if you're running a full archive node (or have access to a full archive node through the RPC). The RPC's eth_getBalance takes a block argument. If you don't have a full archive node, your only recourse is to build the balance from the transactions which is not easy in a decentralized way (but is not too hard using the fully-centralized Etherscan).


On this, you can do checkpoints in Solidity (save a state and then query from that state at a block number):

Here's an example: https://github.com/Giveth/minime/blob/master/contracts/MiniMeToken.sol

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.