1

I am looking way to create a report on how specific function responses change block by block.

Something like:

   const responses = []

   
   for(let i = 0; i < blockNumberList.length; i++){
     const blockNumber = blockNumberList[i]
     const response = await contract.foo() // <-- should return response by block number
     responses.push(response)
   } 

What I do now:

I have hardhat project with config like:

hardhat: {
  forking: {
    url: ''https://mainnet.infura.io/v3/key',
      blockNumber: 13413700,
    },
},

and function call like:

  const response = contract.func()

If I change manually blocknumber and restart harhad console, I get different responses by blocknumber.

I am looking more efficient way to collect responses than collect then manually changing config.

2
  • I do not understand. A transaction cannot know in which block it will be included and you cannot force a transaction to be included into a specific block. So what are you trying to achieve exactly ? Commented Oct 14, 2021 at 13:07
  • @Itération122442 Look I updated the question, I tried explaining how I deal with it now. Commented Oct 14, 2021 at 15:53

1 Answer 1

0

For view functions, ethers.js allow a blockTag override.

for(let i = 0; i < blockNumberList.length; i++){
  const blockNumber = blockNumberList[i]
  const response = await contract.foo({
    blockTag: blockNumber
  })
} 

For this, you need an archive node (I think you already have that arranged since you are using hardhat mainnet fork, but just mentioning here).

Some backends who are not archive nodes, they silently ignore the blockTag and give you state for latest block, you may have to watch out for that as well :P

2
  • no need to use archive nodes if using web3.js, ethers.js quite weird Commented Mar 3, 2022 at 22:43
  • I tried that with this function: ``` const generateContractFunctionList = tokens => tokens.map(({ address: tokenAddress, symbol }) => contract(symbol, abi, tokenAddress).balanceOf(walletAddress, {blockTag: blockNumber}), ); ``` But I got this error Error: types/values length mismatch (count={"types":1,"values":2}, value={"types":[{"name":"_owner","type":"address","indexed":null,"components":null,"arrayLength":null,"arrayChildren":null,"baseType":"address","_isParamType":true}],"values":["<myaddress>",{"blockTag":"12155258"}]}, code=INVALID_ARGUMENT, version=abi/5.5.0) Commented Mar 8, 2022 at 23:56

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.