According to the truffle documentation, the two arguments gas
and gasPrice
stand for:
For the gasPrice: it's easy, higher is the price, faster your transaction will be mined. On the testnet (Ropsten), as the ether doesn't worth anything, you can probably pass a large value (100Gwei for instance).
However, on the mainnet: I recommend to check EthGasStation to estimate the time for a transaction to be mined depending on the gasPrice passed.
About the gas: you have to pass the maximum units of gas that can be consumed by the transaction.
I have done a simple JavaScript script (using Truffle Metacoin contract) that can help you to estimate the gas for a contract deployment.
a. In truffle project directory, create a file estimate_deployment.js
var MetaCoin = artifacts.require("./MetaCoin.sol");
var solc = require('solc')
module.exports = function(callback) {
MetaCoin.web3.eth.getGasPrice(function(error, result){
var gasPrice = Number(result);
console.log("Gas Price is " + gasPrice + " wei"); // "10000000000000"
var MetaCoinContract = web3.eth.contract(MetaCoin._json.abi);
var contractData = MetaCoinContract.new.getData({data: MetaCoin._json.bytecode});
var gas = Number(web3.eth.estimateGas({data: contractData}))
console.log("gas estimation = " + gas + " units");
console.log("gas cost estimation = " + (gas * gasPrice) + " wei");
console.log("gas cost estimation = " + MetaCoin.web3.fromWei((gas * gasPrice), 'ether') + " ether");
});
};
When executing the script
$ truffle exec estimate_deployment.js
Using network 'development'.
Gas Price is 20000000000 wei
gas estimation = 266000 units
gas cost estimation = 5320000000000000 wei
gas cost estimation = 0.00532 ether
So in your case, truffle.js file will look like:
ropsten: {
provider: ropstenProvider,
gas: 266000,
gasPrice: web3.toWei("50", "gwei"),
network_id: "3"
}
CODE AVAILABLE HERE