# Tạo lock contract **Published by:** [tonythanh2012](https://paragraph.com/@tonythanh/) **Published on:** 2023-04-18 **URL:** https://paragraph.com/@tonythanh/t-o-lock-contract ## Content // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; // 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); } } ## Publication Information - [tonythanh2012](https://paragraph.com/@tonythanh/): Publication homepage - [All Posts](https://paragraph.com/@tonythanh/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@tonythanh): Subscribe to updates