i'm noob, I want to deploy my contract on Ropsten network with MetaMask & Truffle, plz explain to me the steps to deploy it.
1 Answer
Solution 1: With you own node
You can easily deploy on the ropsten network if you own a full node running on your machine.
i. Run geth
$ geth --fast --cache=1048 --testnet --unlock "0xmyaddress" --rpc --rpcapi "eth,net,web3" --rpccorsdomain '*' --rpcaddr localhost --rpcport 8545
ii. In truffle.js, add the following configure for the ropsten network
module.exports = {
networks: {
localhost: {
host: "localhost",
port: 8546,
network_id: "*"
},
ropsten: {
host: "localhost",
port: 8545,
network_id: "3"
}
}
};
iii. Deploy on the ropsten network
$ truffle migrate --network ropsten
Solution 2: With a public node like Infura
i. Install the needed libraries
Navigate into the project folder and run the following command:
npm init
npm install truffle-hdwallet-provider --save
ii. In truffle.js, Add the following code to unlock your Metamask account and configure the Infura Ropsten node as entry point by providing the mnemonic phrase (Metamask / Settings / Reveal Seed Words)
var HDWalletProvider = require("truffle-hdwallet-provider");
var infura_apikey = "XXXXXX";
var mnemonic = "twelve words you can find in metamask/settings/reveal seed words blabla";
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
}
}
};
iii. Deploy on the ropsten network
$ truffle migrate --network ropsten
EDIT: Replace the solution by truffle-hdwallet-provider
.Way more simple solution than ethereumjs-wallet bip39 web3-provider-engine web3
-
3
-
With the first solution, you need a local synchronised full node (all blocks). The second solution relies on a third party with a fully synchronised node, you don't need a node at all Jul 31, 2017 at 11:30
-
1i have error when i run second solution Error: Cannot find module 'ethereumjs-wallet/hdkey'– TahaBAJul 31, 2017 at 12:38
-
Hi, sorry I forgot one point in the second solution. You need to execute this command first:
npm install ethereumjs-wallet bip39 web3-provider-engine web3 --save
(I edited the answer with the details) Aug 1, 2017 at 9:43 -
1I pushed my code on github to give you an example : github.com/gjeanmart/stackexchange/tree/master/… Aug 1, 2017 at 22:03