松露/甘纳许:是否可以设置部署地址?

时间:2019-03-24 13:17:32

标签: ethereum solidity truffle ganache

我目前正在Solidity中开发一个dapp,并希望经常在更新中对其进行本地测试-因此,我真的不想每次都将其重新部署到测试网中。 但是,每次部署它时,智能合约的部署地址都会更改,因此我必须将前端代码更新为新地址。

是否有一种“强制”智能合约始终部署在同一地址的方法?还是您可能想到的其他等效解决方案?

谢谢!

2 个答案:

答案 0 :(得分:1)

遇到同样的问题。我不知道这是否合法,但您可以这样做:

  

在您的迁移文件( 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

答案 1 :(得分:0)

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

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