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(https://infura.io/)
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: 8545,
network_id: "*"
},
ropsten: {
host: "localhost",
port: 8545,
gas: 4700000,
gasPrice: 1000000000,
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 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";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
Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News
Also, Read
- Copy Trading | Crypto Tax Software
- Grid Trading | Crypto Hardware Wallet
- Crypto Telegram Signals | Crypto Trading Bot
- Best Crypto Exchange | Best Crypto Exchange in India
- Best Crypto APIs for Developers
- Best Crypto Lending Platform
- An ultimate guide to Leveraged Token