【区块链】部署智能合约到以太坊主网(truffle+infura)

环境

  • win10
  • nodev8.9.4
  • truffle

注册infura获取API-KEY

  • https://infura.io/

编写truffle配置文件

  • npm install truffle-hdwallet-provider
  • truffle-config.js

var HDWalletProvider = require("truffle-hdwallet-provider"); 

// infura 注册后获取的api-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
    }
  }
};

部署到主网

  • 执行如下命令,部署到以太坊主网
truffle migrate --network main

备注

  • 获取Ropsten测试网的测试ETH币:http://faucet.ropsten.be:3001/

你可能感兴趣的:(区块链)