I'm trying to integrate a contract into a front end with MetaMask and getting different gas amounts depending on the network and compile options I use.

  • Remix ("Enable Optimization" checked): 90,410

  • Ganache/Rinkeby (no optimization): 112,500

  • Ganache/Rinkeby (with optimization): 101,431

I actually got the optimization settings from the Remix GitHub page here: https://github.com/ethereum/remix-ide/blob/14c22658ef5b6aa49ee31d5c92882c8a3c9e42fe/src/app/compiler/compiler-input.js

My solc configuration looks like this. The only change I'm making to optimize is to add the optimizer setting below.

let jsonContractSource = JSON.stringify({
    language: 'Solidity',
    sources: {
      'Task': {
          content: source,
    settings: { 
      optimizer: {
        enabled: true,
        runs: 200
      outputSelection: {
          '*': {
              '*': ['abi',"evm.bytecode"],   

module.exports = JSON.parse(solc.compile(jsonContractSource)).contracts.Task.MyContract;

I spent a decent amount of time trying to optimize the gas consumption of the function itself in Remix, but I think I must be missing something in terms of solc configuration.

As an additional question, are there any risks associated with using solc's optimizer?

  • What code are you testing with? If you use the same version of the compiler and optimization parameters they should produce the same gas consumption.
    – Ismael
    Jun 30, 2019 at 21:15
  • I just noticed a few minutes ago that if I test in Ganache or Rinkeby through Remix, I get a similar gas cost to a contract compiled with solc. I think it might just be an issue with Remix's Javascript VM not being reflective of real networks. Jun 30, 2019 at 21:25


Your Answer

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

Browse other questions tagged or ask your own question.