Skip to content

Instantly share code, notes, and snippets.

@DoguD
Created September 11, 2022 11:35
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 DoguD/5385d35cf3562ccdb2af3cc05739111b to your computer and use it in GitHub Desktop.
Save DoguD/5385d35cf3562ccdb2af3cc05739111b to your computer and use it in GitHub Desktop.
Basic Solidity contract to tell the seconds past after update function calls.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract StopWatch {
uint256 lastUpdateTimestamp;
constructor() {
lastUpdateTimestamp = block.timestamp;
}
function getSecondsSinceLastUpdate() public view returns(uint256) {
return block.timestamp - lastUpdateTimestamp;
}
function update() public {
lastUpdateTimestamp = block.timestamp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment