Skip to content

Instantly share code, notes, and snippets.

@Jesserc
Last active August 5, 2022 23:13
Show Gist options
  • Save Jesserc/647dd037e3311f7ae4d9c8869049aaab to your computer and use it in GitHub Desktop.
Save Jesserc/647dd037e3311f7ae4d9c8869049aaab to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Staking {
mapping(address => uint256) balances;
uint256 public deadline = 0;
event Stake(address sender, uint256 amount);
function stake() public payable {
require(msg.value > 0, "Input value");
require(block.timestamp > deadline, "Wait until 30sec");
balances[msg.sender] += msg.value;
emit Stake(msg.sender, msg.value);
updateDeadline(block.timestamp + 30 seconds);
}
function withdraw() public payable {
require(block.timestamp > deadline, "");
require(balances[msg.sender] > 0, "No amount staked");
payable(msg.sender).transfer(balances[msg.sender]);
}
function updateDeadline(uint256 _deadline) private {
deadline = _deadline;
}
function timeLeft() public view returns (uint256) {
return deadline - block.timestamp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment