1

I'd like to configure my Hardhat node to start at a specific timestamp t, where t is less than the current timestamp Tc. The goal is to replay past mainnet transactions locally by setting the exact timestamp, and potentially even the block number, at which these transactions occurred.

While Hardhat's time.increaseTo method allows altering the time to a time later than the current unix time, it doesn't offer the capability to specify an initial timestamp in the past. For example, if I want to replay transactions A, B, and C, which occurred at times 1000, 1003, and 1008 respectively, and the current time is 1_000_000, I can:

  1. Replay transaction A.
  2. Use time.increaseTo(1_000_003) to set the time before replaying transaction B.
  3. Use time.increaseTo(1_000_008) to set the time before replaying transaction C.

But this approach is not flexible enough for scenarios where having control over the exact timestamp and block number is crucial. Is there a way to set these properties when starting a local Hardhat node?

1 Answer 1

1

Yes, Hardhat allows you to set a specific block number for your local node.

To add a block number, you just need to include it in your hardhat.config.js file:

networks: {
    hardhat: {
      blockConfirmations: 1,
      forking: {
        url: process.env.FORKING_URL,
        blockNumber: 17372500,
      },
    },

Now, whenever you start your local node, it will start at the block number you've specified.

2
  • 2
    This is using a forked node, I want to achieve this and also setting a start time, without forking
    – MShakeG
    Commented Sep 20, 2023 at 18:45
  • @MShakeG I see your point, the local node always uses default block number of 0 initially, and currently, I don't know of a way to change it inside the hardhat.config. I've opened an issue and cited your question so hopefully, Nomic can either educate us on this or add it as a new feature. UPDATE: I just saw that you also created an issue about this lol.
    – Rohan Nero
    Commented Sep 20, 2023 at 21:42

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.