【问题标题】:Best way to configure truffle `from` address配置松露`from`地址的最佳方法
【发布时间】:2018-11-06 05:23:27
【问题描述】:
我正在设置我的 truffle 配置文件,并且我正在从 env 变量中设置 from 地址,如下所示:
module.exports = {
networks: {
local: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
from: process.env.OWNER,
}
}
};
然后我运行OWNER=<address> truffle migrate --network local
有什么更好的方法来做到这一点,让松露使用 ganache 生成的第一个地址?
【问题讨论】:
标签:
solidity
smartcontracts
truffle
【解决方案1】:
如果您在truffle.cfg 中省略from 参数,它将自动默认为您连接到的提供商处web3.eth.getAccounts 返回的第一个帐户。
如果您想对所使用的帐户进行更多动态控制,可以使用deployer 进行控制。
var SimpleContract = artifacts.require("SimpleContract");
module.exports = function(deployer, network, accounts) {
deployer.deploy(SimpleContract, { from: accounts[1] }); // Deploy contract from the 2nd account in the list
deployer.deploy(SimpleContract, { from: accounts[2] }); // Deploy the same contract again (different address) from the 3rd account.
};
当然,您不必使用传入的帐户列表,您可以从您想要的任何其他数据源中提取列表。如果你想拥有特定于环境的逻辑,你也可以使用network。