使用MetaMask+Truffle部署合约

2019-01-16  本文已影响26人  arthur25

Steps to deploy a contract using MetaMask and Truffle

Deploy smart contract on Ropsten network with MetaMask & Truffle. Two solutions to start with, one is to run your own geth node which consumes lot of cpu from your machine. In my MacBook Pro, running a geth node for 15 minutes will drain the full battery and the other solution is to connect with a public node like infura

Solution 1: With you own node

You can easily deploy on the ropsten network if you own a full node running on your machine.

$ geth --fast --cache=1048 --testnet --unlock "0xmyaddress" --rpc --rpcapi "eth,net,web3" --rpccorsdomain '*' --rpcaddr localhost --rpcport 8545
module.exports = {
  networks: {
    localhost: {
      host: "localhost", 
      port: 8545,
      network_id: "*" 
    },  
    ropsten: {
      host: "localhost",
      port: 8545,
      gas: 4700000,
      gasPrice: 1000000000,
      network_id: "3"
    }
  }
};
truffle migrate --network ropsten
Solution 2: With a public node like Infura
var HDWalletProvider = require("truffle-hdwallet-provider");
var infura_apikey = "XXXXXX";
var mnemonic = "twelve words you can find in metamask/settings/reveal seed words";
module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    ropsten: {
      provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/"+infura_apikey),
      network_id: 3
    }
  }
};
$ truffle migrate --network ropsten

上一篇 下一篇

猜你喜欢

热点阅读