在我的稳固合同中,我有以下方法。
function deploy(bytes memory bytecode, uint _salt) public payable returns (address){
address addr;
assembly {
addr := create2(
callvalue(),
add(bytecode, 0x20),
mload(bytecode),
_salt
)
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
emit Deployed(addr, _salt);
}如果我的字节码长为2000个字符,并且部署了契约,则该方法可以工作。但是,当字节码的长度为10000个字符时,没有部署契约,并且正在调用还原。create2的字节码大小有限制吗?
发布于 2021-11-18 19:46:56
如果您能够编译代码,那么使用create2部署合同就不会有任何问题。最大合同大小限制为24 of。如果这是问题所在,请查看这或这。
您应该使用creationCode而不是runtimeCode。有关更多信息,请访问文档。
尝试在混炼上运行此示例以测试如何使用用Create2 2预计算合同地址。在TestContract函数中添加您的合同并用您的合同名称(type(YOUR_CONTRACT_NAME). creationCode )更新_foo和使用您的契约构造函数参数更新D8。
function getBytecode(address _owner, uint _foo) public pure returns (bytes memory) {
bytes memory bytecode = type(TestContract).creationCode;
return abi.encodePacked(bytecode, abi.encode(_owner, _foo));
}如果尝试使用相同的salt部署相同的字节码,则此代码将恢复。
https://ethereum.stackexchange.com/questions/113848
复制相似问题