知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
安裝 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