首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Create2在不同的网络上提供不同的地址

Create2在不同的网络上提供不同的地址
EN

Ethereum用户
提问于 2022-07-09 01:15:53
回答 1查看 69关注 0票数 0

我正在尝试使用create2方法在两个网络上部署一个契约。我在Goerli和Rinkeby中使用了相同的参数,但是对于相同的契约,我仍然得到两个不同的地址。

下面是我使用的代码,从另一个教程中提取

代码语言:javascript
复制
// 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;
    }
}
EN

回答 1

Ethereum用户

发布于 2023-04-24 19:41:16

你的工厂地址在两个网络上都是一样的吗?

验证工厂地址在两个网络上都是相同的,并且在两个网络上使用相同的盐分。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/131443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档