Go-Ethereum
燃燒乙太幣和其他乙太坊代幣的最佳方式?
發送到地址 0x0000000000000000000000000000000000000000 的任何乙太幣或代幣都將被銷毀,這是否正確?
或者燃燒乙太幣/代幣的最佳方式是什麼?
根據 Jeff Wilcke的說法,銷毀 ETH 的正確方法是創建一個合約,該合約會立即自毀並發送到自己的地址,或者只是將乙太幣發送到他部署的合約,這一切都會為你完成:
https://etherscan.io/address/0xb69fba56b2e67e7dda61c8aa057886a8d1468575#code
這是程式碼:
pragma solidity ^0.4.11; contract Burner { uint256 public totalBurned; function Purge() public { // the caller of purge action receives 0.01% out of the // current balance. msg.sender.transfer(this.balance / 1000); assembly { mstore(0, 0x30ff) // transfer all funds to a new contract that will selfdestruct // and destroy all ether in the process. create(balance(address), 30, 2) pop } } function Burn() payable { totalBurned += msg.value; } }
一個沒有組裝的更簡單的例子是:
contract GetsBurned { function () payable { } function BurnMe () { // Selfdestruct and send eth to self, selfdestruct(address(this)); } }
呼叫
BurnMe
第二個範例後,您會看到合約的地址不再有任何餘額或程式碼。ETH 就這樣消失了!
如果您只需要銷毀在乙太坊平台上開發的代幣,則可以將此功能嵌入到智能合約本身中:
/** * @dev Burns a specific amount of tokens. * @param _value The amount of token to be burned. */ function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); // no need to require value <= totalSupply, since that would imply the // sender's balance is greater than the totalSupply, which *should* be an assertion failure address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); Burn(burner, _value); }
如果您開發自己的集中式令牌,您可能希望嵌入一些額外的安全檢查,例如驗證函式呼叫者的地址。