知乎专栏 | 多维度架构 |
安装 truffle-hdwallet-provider
$ npm install truffle-hdwallet-provider
修改 truffle.js 文件
var HDWalletProvider = require("truffle-hdwallet-provider"); // infura 为你提供的 apikey 请与你申请到的 key 保持一致 var infura_apikey = "CsS9shwaAab0z7B4LP2d"; // 你以太坊钱包地址 进入 MetaMask -> Settings -> reveal seed words 复制到此处 var mnemonic = "drill hunt food team moment mistake bird attitude tunnel ecology sister resist"; module.exports = { networks: { development: { host: "127.0.0.1", port: 7545, network_id: "*" }, private: { host: "localhost", port: 8545, network_id: "*" // Match any network id }, ropsten: { provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/"+infura_apikey), network_id: 3, gas: 3012388, gasPrice: 30000000000 }, main: { provider: new HDWalletProvider(mnemonic, "https://mainnet.infura.io/"+infura_apikey), network_id: 3, gas: 3012388, gasPrice: 1000000000 } } };
部署合约到 ropsten 测试网, 在命令行输入如下命令,通过 --network 设置发布的目标网络:
truffle migrate --network ropsten
主网络发布
truffle migrate --network main