当配置有 2 个网络时,truffle 默认迁移到哪个网络?
What network does truffle migrate to as default when the config has 2 networks?
对于下面的 truffle-config.js 文件,它在 module.exports 中列出了 2 个网络(开发和 ropsten),如果我使用命令 truffle migrate 在终端中没有明确说明 --network development 或 --network ropsten,合约将部署到哪个网络?两个?
require('dotenv').config();
const Web3 = require("web3");
const web3 = new Web3();
const WalletProvider = require("truffle-wallet-provider");
const Wallet = require('ethereumjs-wallet');
const ropstenPrivateKey = new Buffer(process.env.ROPSTEN_PRIVATE_KEY, "hex")
const ropstenWallet = Wallet.fromPrivateKey(ropstenPrivateKey);
const ropstenProvider = new WalletProvider(ropstenWallet, `https://ropsten.infura.io/${process.env.INFURA_ROPSTEN_ID}`);
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
ropsten: {
provider: ropstenProvider,
gas: 4600000,
gasPrice: web3.utils.toWei('55', 'gwei'),
network_id: "3"
}
}
};
如果未指定 --network
,则仅部署到 development
。您可以通过 运行 迁移来确认这一点:
$ truffle migrate
Compiling .\contracts\SimpleContract.sol...
Writing artifacts to .\build\contracts
Using network 'development'.
Network up to date.
对于下面的 truffle-config.js 文件,它在 module.exports 中列出了 2 个网络(开发和 ropsten),如果我使用命令 truffle migrate 在终端中没有明确说明 --network development 或 --network ropsten,合约将部署到哪个网络?两个?
require('dotenv').config();
const Web3 = require("web3");
const web3 = new Web3();
const WalletProvider = require("truffle-wallet-provider");
const Wallet = require('ethereumjs-wallet');
const ropstenPrivateKey = new Buffer(process.env.ROPSTEN_PRIVATE_KEY, "hex")
const ropstenWallet = Wallet.fromPrivateKey(ropstenPrivateKey);
const ropstenProvider = new WalletProvider(ropstenWallet, `https://ropsten.infura.io/${process.env.INFURA_ROPSTEN_ID}`);
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
ropsten: {
provider: ropstenProvider,
gas: 4600000,
gasPrice: web3.utils.toWei('55', 'gwei'),
network_id: "3"
}
}
};
如果未指定 --network
,则仅部署到 development
。您可以通过 运行 迁移来确认这一点:
$ truffle migrate
Compiling .\contracts\SimpleContract.sol...
Writing artifacts to .\build\contracts
Using network 'development'.
Network up to date.