lifemathmoney

etherLock.sol

May 11th, 2021 (edited)
809
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //SPDX-License-Identifier: AFL-3.0 (Academic Free License v3.0) https://opensource.org/licenses/afl-3.0
  2. //code by Harsh Strongman from lifemathmoney.com, the #1 self-improvement website for men
  3.  
  4. //solidity version specifier
  5. pragma solidity 0.8.1;
  6.  
  7. //This contract locks in Ether for 1 year to help the owner with a savings habit
  8.  
  9. contract etherLock {
  10.    
  11.     address payable owner;
  12.     uint startTime;
  13.    
  14.     //Set the start time to when the contract is created and save the creator's address
  15.     constructor() {
  16.         owner = payable(msg.sender);
  17.         startTime = block.timestamp;
  18.     }
  19.    
  20.     //function to recieve ether
  21.     receive() external payable {}
  22.    
  23.     function withdraw() public {
  24.         //check if 1 year has passed
  25.         require((block.timestamp - startTime) > 1 years, "1 year has not yet passed");
  26.         //send ether
  27.         owner.transfer(address(this).balance);
  28.     }
  29. }
RAW Paste Data