【问题标题】:Truffle/Ganache: is there a way to set a deployment address?Truffle/Ganache:有没有办法设置部署地址?
【发布时间】:2019-08-14 21:23:43
【问题描述】:

我目前正在使用 Solidity 开发一个 dapp,并希望经常在本地测试它以及更新 - 所以我真的不想每次都将它重新部署到测试网络。 但是,每次我部署它时,智能合约的部署地址都会发生变化,所以我必须将我的前端代码更新到新地址。

有没有办法“强制”智能合约始终部署在同一个地址?或者您可能会想到其他等效的解决方案吗?

谢谢!

【问题讨论】:

标签: ethereum solidity truffle ganache


【解决方案1】:

您可以通过在follows 文件中传递follows 之类的帐户参数来获取您拥有的帐户列表:

module.exports = function(deployer, network, accounts) {
  // Use the accounts within your migrations.
}

【讨论】:

    【解决方案2】:

    面临同样的问题。我不知道这是否合法,但你可以这样做:

    在您的迁移文件中 (migrations/1_example_migration.js)

    var MyContract = artifacts.require("MyContract");
    
    module.exports = function(deployer) {
        console.log(deployer);
        console.log(arguments);
        let n = 5; // it can be any address from list of available
        deployer.deploy(MyContract, {from: arguments[2][n]});
    };
    

    Documentation

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 2022-07-18
      • 2020-04-10
      • 2018-10-30
      • 1970-01-01
      相关资源
      最近更新 更多