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
I believe the error message you're getting is probably coming from Infura (the node MetaMask connects to by default). So, there's no way to fix this for the final user in order that the error comes from a 3rd party.
- If you don't care about migrating from the interface, you can run your own node and use Mist or geth. Or you could sign transactions offline and broadcast them via etherscan.io. Other than those options.
- If at a certain point you discover an Infura node that works OK and doesn't give you that error, you can always point to it in order to don't get the error repeated.
Otherways, you'll be obligated to change manually the Gas Price manually, which in most cases isn't that bad trust me. Lots of people have lost many money by extremely high Gas Prices paid.
Hope it helps.
Best Answer
You can achieve this without sending any actual transactions.
After this you can multiple the
gasprice
of the network with theestimated gas
of thecontract deployment
to get theactual price
to deploy contract and you can do this with every transaction you want to send