I just want to test my smart contract to be deployed in the Ropsten network, and I'm still puzzled on what should I put for the gas and gasPrice in the Truffle config. Thoughts about this?

ropsten: {
  provider: ropstenProvider,
  gas: 4600000,
  gasPrice: web3.toWei("50", "gwei"),
  network_id: "3"

2 Answers 2


According to the truffle documentation, the two arguments gas and gasPrice stand for:

  • gas: Gas limit used for deploys. Default is 4712388.

  • gasPrice: Gas price used for deploys. Default is 100000000000 (100 Shannon).

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"


  • What is the unit in the truffle.js configuration file?
    – 0xgoku
    Feb 20, 2018 at 6:04
  • 1
    This is super helpful. It'd be even more helpful if there was an example of updated syntax with web3.eth.Contract. I'm stuck trying to figure out how to get the contract data .. the new way.
    – Kirby
    Mar 23, 2020 at 18:14
  • truffle migrate --reset --network mainnet --dry-run
    – Kirby
    Mar 23, 2020 at 18:22
  • Need to update web3.eth.contract to new web3.eth.Contract but then it still won't work with Cannot read property 'getData' of undefined Sep 8, 2020 at 2:29

gas is a unit for step execution which is defined in EVM. Creation of a contract is a transaction which will cost gas. gasCost will specify how much your willing to pay for each step.

Coming to your ropsten config, your specifying how much gas units EVM can take to deploy into ropsten network.

Total transaction value = gas*gasPrice.

Let assume if your contract deploying might take total 100 wei, but you supplied as 200 gwi. EVM will return remaining gas to you. If you passed less than value what it will require then it will deduct amount from your account and transaction is failed. i.e it will not deploy your smart contract into the network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.