是否可以在销毁(使用selftDestruct函数)的同时生成相同的契约?
我们假设第一个约定是拥有1Eth,然后将所有的eth提取到另一个erc20地址,在完全提取之后,第一个约定调用自销毁函数,然后重新部署相同的约定,并在循环中。
也许最简单的方法是使用条件函数?
发布于 2021-11-25 00:24:29
不可能“同时”,需要在单独的事务中做。
selfdestruct阻止对约定的后续操作,并将约定标记为删除。
但是,EVM直到事务处理结束时才删除其字节码。因此,在下一次tx之前,您将无法将新字节码部署到相同的地址。
pragma solidity ^0.8;
contract Destructable {
function destruct() external {
selfdestruct(payable(msg.sender));
}
}
contract Deployer {
function deployAndDestruct() external {
Destructable destructable = new Destructable{salt: keccak256("hello")}();
destructable.destruct();
// The second deployment (within the same transation) causes a revert
// because the bytecode on the desired address is still non-zero
Destructable destructable2 = new Destructable{salt: keccak256("hello")}();
}
}https://stackoverflow.com/questions/70103433
复制相似问题