0

I want to get the current block number of all blocks. If I run return block.number it only returns me the number of blocks since the last deploy.

Why is it like that?

1 Answer 1

0

I think you are using the Remix VM environment.

enter image description here

This environment is in memory and Remix only generates new blocks when someone deploys something or sends a transaction. Therefore you are getting the latest generated block when you deployed the contract

to have what you want you can download and start Ganache and then connect Ganache to remix (limitation: i think you will not be able to debug transactions)

enter image description here

Remember to disable "auto mine" in Ganache, otherwise, it will work as Remix did

enter image description here

Update: there is also another way (commands using the console) to change the time and this will generate empty new blocks. but this is another question :D

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.