合同被杀死但收到以太币
Contract killed but receive Ether
我对solidity中的selfdestruct函数有疑问。我在下面有这份合同:
pragma solidity ^0.4.25;
contract TestMetamask {
string public name = "Joao";
event EtherReceived();
function changeName(string _name) public {
name = _name;
}
function() public payable {
emit EtherReceived();
}
function receiveEther() payable public {
address(this).transfer(msg.value);
}
function balance() public view returns (uint256) {
return address(this).balance;
}
function kill() public {
selfdestruct(msg.sender);
}
}
所以这个合约有效,但是当我执行函数 kill() 时,合约一直在函数 payable receiveEther 中接收以太币。
另一个函数不起作用并且状态变量是干净的,问题仅在于合约被破坏接收以太币。
这是 rinkeby 的合约地址:
https://rinkeby.etherscan.io/address/0xe0491e86b972ae4b0f8359a6066b79256ea01274
有没有人遇到过同样的情况?
谢谢。
自毁后,仍可向合约发送以太币,合约将永远丢失。
也请参阅此 stackexchange 问题:https://ethereum.stackexchange.com/questions/46813/what-is-happening-after-a-self-destruct-is-called-for
我对solidity中的selfdestruct函数有疑问。我在下面有这份合同:
pragma solidity ^0.4.25;
contract TestMetamask {
string public name = "Joao";
event EtherReceived();
function changeName(string _name) public {
name = _name;
}
function() public payable {
emit EtherReceived();
}
function receiveEther() payable public {
address(this).transfer(msg.value);
}
function balance() public view returns (uint256) {
return address(this).balance;
}
function kill() public {
selfdestruct(msg.sender);
}
}
所以这个合约有效,但是当我执行函数 kill() 时,合约一直在函数 payable receiveEther 中接收以太币。 另一个函数不起作用并且状态变量是干净的,问题仅在于合约被破坏接收以太币。
这是 rinkeby 的合约地址: https://rinkeby.etherscan.io/address/0xe0491e86b972ae4b0f8359a6066b79256ea01274
有没有人遇到过同样的情况?
谢谢。
自毁后,仍可向合约发送以太币,合约将永远丢失。 也请参阅此 stackexchange 问题:https://ethereum.stackexchange.com/questions/46813/what-is-happening-after-a-self-destruct-is-called-for