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?
solc
. I think it might just be an issue with Remix's Javascript VM not being reflective of real networks. – SuperCodeBrah Jun 30 '19 at 21:25