Created
July 21, 2024 17:32
-
-
Save KBPsystem777/a978883afdc0cc0230710ad47760d0a5 to your computer and use it in GitHub Desktop.
DevUp!: Smart contract build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.24; | |
// Uncomment this line to use console.log | |
// import "hardhat/console.sol"; | |
contract Lock { | |
uint public unlockTime; | |
address payable public owner; | |
event Withdrawal(uint amount, uint when); | |
constructor(uint _unlockTime) payable { | |
require( | |
block.timestamp < _unlockTime, | |
"Unlock time should be in the future" | |
); | |
unlockTime = _unlockTime; | |
owner = payable(msg.sender); | |
} | |
function withdraw() public { | |
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal | |
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); | |
require(block.timestamp >= unlockTime, "You can't withdraw yet"); | |
require(msg.sender == owner, "You aren't the owner"); | |
emit Withdrawal(address(this).balance, block.timestamp); | |
owner.transfer(address(this).balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment