For Ganache, there are several solutions.

What about Hardhat? They implemented their own local blockchain, Hardhat Network, which is different to Ganache.

  • 1
    The buidlerevm page says it supports ganache's evm_increaseTime and additionally they have evm_setNextBlockTimestamp.
    – Ismael
    Aug 12 '20 at 0:16
  • @Ismael your comment is a legitimate answer. Feel free to post it :) Aug 12 '20 at 9:43
  • I can't test right now, but I'll add an answer when I've more time.
    – Ismael
    Aug 12 '20 at 21:12

There are two relevant RPC methods here: evm_increaseTime and evm_setNextBlockTimestamp. In both cases, they affect the next block but don't mine one.

evm_increaseTime receives a number of seconds that will be added to the timestamp of the latest block. evm_setNextBlockTimestamp receives an absolute UNIX timestamp (again, in seconds), and so it's not affected by the current block.



// suppose the current block has a timestamp of 01:00 PM
await network.provider.send("evm_increaseTime", [3600])
await network.provider.send("evm_mine") // this one will have 02:00 PM as its timestamp


await network.provider.send("evm_setNextBlockTimestamp", [1625097600])
await network.provider.send("evm_mine") // this one will have 2021-07-01 12:00 AM as its timestamp, no matter what the previous block has

Keep in mind that Hardhat Network validates that the new timestamp is bigger than the previous one, so you can't send any value.

  • When using this with hardhat I got this issue: Error: Transaction reverted and Hardhat couldn't infer the reason. Please report this to help us improve Hardhat. Mar 7 '21 at 17:16
  • Did anyone face the same issue ? Mar 7 '21 at 17:16
  • @Franco this way also works: await network.provider.send("evm_mine", [timestampInSeconds]);
    – Russo
    Oct 1 '21 at 9:27

A new update to ganache has added a time parameter to the evm_mine command. Now the best way to move time is

await ethers.provider.send("evm_mine", [newTimestampInSeconds]);

It is better because you only make 1 RPC call instead of 2 in the accepted solution.

Note that you can't move time backword in hardhat.


What I've been using with typescript and hardhat:

import { ethers, waffle } from 'hardhat';

const time = now + 86400
await ethers.provider.send('evm_setNextBlockTimestamp', [now]); 
await ethers.provider.send('evm_mine');
  • This doesn't seem to work for me in hardhat currently, if I log out the result of the first call, I get the new time I'm trying to set to, but further assertions down the line don't seem to respect that new time. Also, I had to add an empty array after the evm_mine argument since its required.Logging out thee result of the evm_mine call is 0x0
    – snkashis
    May 26 '21 at 19:02
  • Is there a simple way to get now instead of (await ethers.provider.getBlock(await ethers.provider.getBlockNumber())).timestamp?
    – Martian
    Dec 18 '21 at 9:22
  • @Martian just use "latest" instead of fetching the last block number. But other than that change, this is about as short as it gets. 2 days ago
const { expect } = require("chai");
const { ethers } = require('hardhat');

const sevenDays = 7 * 24 * 60 * 60;

const blockNumBefore = await ethers.provider.getBlockNumber();
const blockBefore = await ethers.provider.getBlock(blockNumBefore);
const timestampBefore = blockBefore.timestamp;

await ethers.provider.send('evm_increaseTime', [sevenDays]);
await ethers.provider.send('evm_mine');

const blockNumAfter = await ethers.provider.getBlockNumber();
const blockAfter = await ethers.provider.getBlock(blockNumAfter);
const timestampAfter = blockAfter.timestamp;

expect(blockNumAfter).to.be.equal(blockNumBefore + 1);
expect(timestampAfter).to.be.equal(timestampBefore + sevenDays);

Adding to Franco's answer, there is a plugin that abstracts some of the complexities of handling time directly.

You can look its documentation in https://www.npmjs.com/package/@atixlabs/hardhat-time-n-mine

  • Returns 404. Is it moved to some different place? @GonzaloPetraglia
    – metadata
    Dec 7 '21 at 8:29
  • Fixed the link while this PR is open Jan 3 at 19:05

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.