Lock.sol 1008 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity ^0.8.28;
  3. // Uncomment this line to use console.log
  4. // import "hardhat/console.sol";
  5. contract Lock {
  6. uint public unlockTime;
  7. address payable public owner;
  8. event Withdrawal(uint amount, uint when);
  9. constructor(uint _unlockTime) payable {
  10. require(
  11. block.timestamp < _unlockTime,
  12. "Unlock time should be in the future"
  13. );
  14. unlockTime = _unlockTime;
  15. owner = payable(msg.sender);
  16. }
  17. function withdraw() public {
  18. // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
  19. // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
  20. require(block.timestamp >= unlockTime, "You can't withdraw yet");
  21. require(msg.sender == owner, "You aren't the owner");
  22. emit Withdrawal(address(this).balance, block.timestamp);
  23. owner.transfer(address(this).balance);
  24. }
  25. }