[SOLVED] Calling Smart Contracts Historical Data Functions

Is there a way to call the smart contract view functions at a particular point of time in the past? For example, if I want to find the total supply of an ERC20 Token a couple of months ago.

You have to get the block number from that day, and then you can try to call that function with an archive node with that specific block number, it looks like Moralis.runContractFunction doesn’t have a block number as parameter and you’ll have to use something like web3

Thanks for this. Looks like I am able to use a direct API call with to_date parameter to get this information

Edit: @cryptokid Actually I need some further help here. Would you be able to provide a sample code for something like this. Or even let me know how I can make calls to archive nodes through Moralis.

I got this resolved. Thanks. Posting the code here in case anyone else needs this or something similar. (I am working with web3 on python but I guess it will be somewhat similar with web3js)

from web3 import Web3

w3 = Web3(Web3.HTTPProvider(Moralis Speedy Node URL)

contract_function = w3.eth.contract(address=Contract Address, abi=JSON ABI)

_total_supply = contract_function.functions.totalSupply().call(block_identifier=Block Number)

2 Likes

Nice work @guru241987

Thank you for sharing the solution :man_mechanic: