0

Can anyone explain or point me to a specific source where I can learn about .providers functions. In particular I am trying to understand what this block of code does:

for (let i = 0; i < 257; i++) {
    await ethers.provider.send("evm_increaseTime", [1]);
    await ethers.provider.send("evm_mine", []); 
    console.log(await ethers.provider.getBlockNumber());
  }

I've tried searchintg the etherjs library but I can't search specific info for providers.* functions. Maybe I just don't know how to use the documentation search properly.

Furthermore, I've tried running it with an Alchemy API, apparently the method is unsupported. Is there an equivalent method?

1 Answer 1

0

A provider gives (or provides) you access to a blockchain. There are different types of providers, and I guess Ethers can't provide you documentation on what all different providers support.

In your case, it looks like the code is from some unit test or similar. Functionalities evm_increaseTime and evm_mine are something that exist only in your local blockchain instance and not anywhere in public chains, since they are directly manipulating the blockchain's concept of time and telling the blockchain to mine a block. In any public blockchain such functionality is executed by miners and nobody can tell them what to do.

Those functions are useful for 1) changing the block.timestamp and to test functionality which depends on that and 2) immediately mining the transaction, so the timestamp is used in the newest block.

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.