I have created a smart contract(a standard token smart contract) in solidity and truffle. Now I want to deploy it to ethereum network. I want to use ropsten network because I want to use metamask wallet. How to do it? Or what is the best way to deploy it in ethereum network?
3 Answers
You need to use truffle-hdwallet-provider and provide it your wallet mnemonic. The mnemonic is the 12 word phrase which addresses are created from. The wallet should have testnet ether already loaded, which you can get from faucets.
Here's how I've been deploying to different testnets:
In truffle.js
:
const HDWalletProvider = require('truffle-hdwallet-provider')
const fs = require('fs')
const mnemonic = process.env.MNEMONIC
module.exports = {
networks: {
development: {
host: 'localhost',
port: 8545,
gas: 4500000,
gasPrice: 25000000000,
network_id: '*'
},
kovan: {
provider: new HDWalletProvider(mnemonic, 'https://kovan.infura.io'),
network_id: '*',
gas: 4500000,
gasPrice: 25000000000
},
rinkeby: {
provider: new HDWalletProvider(mnemonic, 'https://rinkeby.infura.io'),
network_id: '*',
gas: 4500000,
gasPrice: 25000000000
},
mainnet: {
provider: new HDWalletProvider(mnemonic, 'https://mainnet.infura.io'),
network_id: '*',
gas: 4500000,
gasPrice: 25000000000
}
}
}
Then just run:
truffle migrate --reset --network=rinkeby
You connect your node to Rospen Revivial (not the orginal Rospen, as its been attacked). Instructions for this are here:
Then you connect your wallet, or geth console, or remix editor (simplest way to develop, work and deploy smart contracts) to the node, and there you go. Some instruction on setting node for RR, and for remix use are here, but there are for cpp-ethereum.
If you want to use Ropsten testnet
, Just launch the ethereum wallet
, it will ask you to connect to main-net or testnet (if a geth instance is not running already). Just choose testNet to connect to Ropsten tetsnet
and you xould easily use the Ethereum-Wallet to deploy your contract.
However, if you want to do the same from the command line. Just run geth --testnet
to connect to Ropsten testnet.