solidity selfdestruct合约销毁

solidity selfdestruct合约销毁

1、部署合约,附带value

2、获取合约地址的eth余额,余额为第一步附带的value

3、调用方法killSelf,进行合约的销毁,并把剩余的ETH转给receiver

solidity 复制代码
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.8.18;

contract Destroy {
    address public owner;

    constructor() payable {
        owner = msg.sender;
    }

    event Receive(address indexed sender, uint256 amount, string data);

    receive() external payable {
        emit Receive(msg.sender, msg.value, "Receive Success");
    }

    function killSelf(address receiver) public {
        require(msg.sender == owner, "Only owner can call this function");

        // // 调用selfdestruct销毁合约,并把剩余的ETH转给receiver
        selfdestruct(payable(receiver));
    }

    // 获取合约地址的eth余额
    function getBalance() public view returns (uint256) {
        return address(this).balance;
    }
}
相关推荐
来了就不要走14 小时前
源达财源滚滚APP怎么样?日常炒股能用得上吗?
区块链
网安蟹佬霸20 小时前
WebAssembly安全攻防实战:从WASM逆向到漏洞利用
前端·安全·自动化·区块链·智能合约·wasm
stockmasterx2 天前
北交所有哪些注意事项?北交所佣金最低是多少?
区块链
网安蟹佬霸2 天前
区块链与智能合约安全实战:从Solidity审计到DeFi漏洞深度剖析
运维·前端·网络·安全·自动化·区块链·智能合约
cmes_love2 天前
期权分钟行情数据下载:商品/股指/ETF期权全覆盖
数据库·区块链
ZDGJ60992 天前
境外期货的交易品种✨
区块链
cd_949217213 天前
让市场“随时买得到、卖得掉” 深澜量化探索流动性服务专业化
大数据·区块链
筱璦3 天前
C# + js通达信/分析家风格指标公式完整内、外期货量化交易系统源码可售
区块链
2401_891409264 天前
【无标题】
区块链
磐链科技5 天前
IM钱包开发核心技术拆解:DID去中心化身份与社交图谱的链上映射
去中心化·区块链