-
Notifications
You must be signed in to change notification settings - Fork 0
/
Week2
27 lines (27 loc) · 875 Bytes
/
Week2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract deathswitch{
address public owner;
uint public lastaliveblock;
address public presetaddress;
modifier onlyOwner() {
require(msg.sender == owner, "Not the owner");
_;
}
constructor(address _presetaddress) onlyOwner{
owner = msg.sender;
presetaddress = _presetaddress;
lastaliveblock = block.number;
}
function stillAlive() external onlyOwner {
lastaliveblock = block.number;
}
function send() external {
require(block.number - lastaliveblock>10,"owner is inactive");
uint balance = address(this).balance;
payable(presetaddress).transfer(balance);
(bool success,)=presetaddress.call{value:balance}("");
require(success, "Transfer failed");
}
receive() external payable {}
}