我正在尝试使用create2方法在两个网络上部署一个契约。我在Goerli和Rinkeby中使用了相同的参数,但是对于相同的契约,我仍然得到两个不同的地址。
下面是我使用的代码,从另一个教程中提取:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Factory {
// Returns the address of the newly deployed contract
function deploy(
address _owner,
uint256 _foo,
bytes32 _salt
) public payable returns (address) {
// This syntax is a newer way to invoke create2 without assembly, you just need to pass salt
// https://docs.soliditylang.org/en/latest/control-structures.html#salted-contract-creations-create2
return address(new SimpleContract{salt: _salt}(_owner, _foo));
}
}
contract SimpleContract {
address public owner;
uint256 public salt;
constructor(address _owner, uint256 _salt) payable {
owner = _owner;
salt = _salt;
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
}发布于 2023-04-24 19:41:16
你的工厂地址在两个网络上都是一样的吗?
验证工厂地址在两个网络上都是相同的,并且在两个网络上使用相同的盐分。
https://ethereum.stackexchange.com/questions/131443
复制相似问题