Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SPDX-License-Identifier: AFL-3.0 (Academic Free License v3.0) https://opensource.org/licenses/afl-3.0
- //code by Harsh Strongman from lifemathmoney.com, the #1 self-improvement website for men
- //solidity version specifier
- pragma solidity 0.8.1;
- //This contract locks in Ether for 1 year to help the owner with a savings habit
- contract etherLock {
- address payable owner;
- uint startTime;
- //Set the start time to when the contract is created and save the creator's address
- constructor() {
- owner = payable(msg.sender);
- startTime = block.timestamp;
- }
- //function to recieve ether
- receive() external payable {}
- function withdraw() public {
- //check if 1 year has passed (1 year has 31536000 seconds)
- require((block.timestamp - startTime) > 31536000, "1 year has not yet passed");
- //send ether
- owner.transfer(address(this).balance);
- }
- }
Add Comment
Please, Sign In to add comment