Skip to content

Instantly share code, notes, and snippets.

@mds1
Created August 26, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mds1/9f41f9421752725df5c954a996cc7a11 to your computer and use it in GitHub Desktop.
Save mds1/9f41f9421752725df5c954a996cc7a11 to your computer and use it in GitHub Desktop.
// Get current block from ganache-cli
let block = await web3.eth.getBlock('latest');
// Log initial timestamp -- logs 1535296387
console.log(block.timestamp);
// Increase time by a huge amount simply to make it easier to distinguish
// between the logged 10-digit numbers (this changes leading digit from a
// 1 to a 2)
await increaseTime(533868440);
// Get the new block number (previous function also mines a block)
block = await web3.eth.getBlock('latest');
// Log new timestamp from ganache-cli -- logs 2069164830 (this is updated)
console.log(block.timestamp);
// Log timestamp returned by the contract from a function that simply
// returns "now" -- logs 1535298108 (this is not updated)
console.log(String(await contract.getTime()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment