智能合约-自毁模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pragma solidity ^0.6.12;

contract SelfDesctructionContract {
address payable owner;

modifier ownerRestricted {
require (owner == msg.sender);
_;
}

// 构造函数
constructor() public {
owner = msg.sender;
}

// 使用ownerRestricted修饰符来限定只有合约的所有者才能调用该函数
function destructContract() public payable ownerRestricted {
selfdestruct(owner);
}
}

owner 必须可接受支付的回收的gas。

关联文档:

  1. 智能合约-CURD的详细分析
  2. 智能合约-自毁模式
  3. 智能合约-工厂合约模式
  4. 智能合约-名字登录模式
  5. 智能合约-退款方式