0

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 ? Oct 14 '21 at 13:07
  • @Itération122442 Look I updated the question, I tried explaining how I deal with it now. Oct 14 '21 at 15:53
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

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.