Skip to content

Instantly share code, notes, and snippets.

@qnxdev
Created March 1, 2022 18:38
Show Gist options
  • Save qnxdev/e3c07252cfebf04a72b1b6db2811e181 to your computer and use it in GitHub Desktop.
Save qnxdev/e3c07252cfebf04a72b1b6db2811e181 to your computer and use it in GitHub Desktop.
Sample Smart Contract Will
// SPDX-License-Identifier: MIT
pragma solidity =0.8.12;
contract Trust {
struct Kid {
uint amount;
uint maturity;
bool paid;
}
mapping(address => Kid) public kids;
address public admin;
/* address public kid;
uint public maturity; */
constructor() payable {
admin = msg.sender;
}
function addKid(address kid, uint timeToMaturity) external payable{
require(msg.sender == admin, 'Admin only feature');
require(kids[kid].amount==0,'Kid already exist');
kids[kid]= Kid(msg.value, block.timestamp + timeToMaturity ,false);
}
/* function addKid(address kid, uint timeToMaturity) external payable{
require(msg.sender==admin, 'Admin only feature');
require(amounts[kid]==0,'Kid already exist');
amounts[kid]=msg.value;
maturities[kid] = block.timestamp + timeToMaturity;
} */
/* constructor(address _kid, uint timeToMaturity) payable {
maturity = block.timestamp + timeToMaturity;
kid= _kid;
} */
function withdraw() external {
Kid storage kid = kids[msg.sender];
require(block.timestamp >= kid.maturity, 'too early withdraw');
require(kid.amount > 0, 'Only kid can withdraw');
require(kid.paid == false, 'Paid already');
kid.paid=true;
payable(msg.sender).transfer(kid.amount);
}
/* function withdraw() external {
require(block.timestamp >= maturities[msg.sender], 'too early withdraw');
require(amounts[msg.sender] > 0, 'Only kid can withdraw');
require(paid[msg.sender] == false, 'Paid already');
payable(msg.sender).transfer(amounts[msg.sender]);
} */
/* function withdraw() external {
require(block.timestamp >= maturity, 'too early withdraw');
require(msg.sender == kid, 'Only kid can withdraw');
payable(msg.sender).transfer(address(this).balance);
} */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment