Truffle compiler seems to generate much longer bytecode when compiling (a bit big) factory contract, making impossible to deploy in testnets or mainnet, due the execution of the deployment is higher than the block gas limit.
On the other side, i can successfully compile and migrate the factory contract from Remix IDE, with same input parameters.
Git clone next repository, switch to LP-000-truffle-error branch
git clone https://gitlab.com/raisehq/contracts-solidity/tree/LP-000-truffle-error
git checkout LP-000-truffle-error
npm i
Start ganache-cli in another terminal:
npx ganache-cli -l 9994805
Run npm run migration -- --reset
It fails while deploying the factory smart contract, latest step in migration. The contract name is LoanContractDispatcher.sol , is a factory contract that can deploy LoanContract.sol .
Not bloated bytecode from truffle compiler. Or at least not twice native Solc, so im able to deploy it using truffle migration scripts, instead of doing it manually using the Remix IDE.
good deploy of LoanContractDispatcher with remix: https://kovan.etherscan.io/tx/0xfdbb287c5547868e80ef7a4dba61a118306917c4272b93adaf56cc1eb2717a2d
Input tx (bytecode) from Remix have a 28654 character length
bad deploy of LoanContractDispatcher with truffle: https://kovan.etherscan.io/tx/0x6f4a9e0e67d56f4d86dad4d8b16868c24c06207f2816736fd20d3767e24559b8
Input tx (bytecode) from Truffle have a 50534 character length
If i set --allowUnlimitedContractSize to ganache-cli i am able to deploy in local, but no way in testnet or mainnet.
Logs from the migration:
Deploying 'LoanContractDispatcher'
----------------------------------
> transaction hash: 0x91f6af7b5ab192aebffe82416e74a008269d89209275e9d868ffec1353c30837
Error: Error: Error: *** Deployment Failed ***
"LoanContractDispatcher" -- The contract code couldn't be stored, please check your gas limit..
at Object.run (/home/kartojal/hero/contracts-solidity/node_modules/truffle/build/webpack:/packages/migrate/index.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.0 (core: 5.1.0)
Node v10.16.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] migration:kovan: `truffle migration --network kovan`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] migration:kovan script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kartojal/.npm/_logs/2019-11-20T15_09_31_319Z-debug.log
truffle version): 5.1.0node --version): Tried with the following versions: v10, v11 and v12npm --version): default npm version from nvm when installing different node versions.Tried with solcjs and solc binary from Docker, 0.5.10 and 0.5.13
is this issue related? https://github.com/trufflesuite/truffle-compile/issues/77
Currently this issue makes me impossible to continue using Truffle for this project, so any workarounds are welcome.
If i use solc 0.5.13 directly, without truffle, i got a bytecode of 28654 character length, matching Remix IDE bytecode.
Thanks for raising this @kartojal, we'll have to look into it! Not sure offhand what's causing this.
Can I work on it ?
Ok. There is an error in truffle-config.js in this project.
It is:
// Configure your compilers
compilers: {
solc: {
version: "0.5.13",
optimizer: {
enabled: true,
runs: 200
}
}
},
But should be:
compilers: {
solc: {
version: "0.5.13",
settings:{
optimizer: {
enabled: true,
runs: 200
}
}
}
},
Optimizer settings must be included in settings object in config file.
As it is described on truffle website in
compiler configuration section
Once you change it then truffle will produce shorter bytecode, 28462 characters long.
Btw. This migration file will still fail, but because of another issue.
Gas estimation for LoanContractDispatcher.setAdministrator: 0.00089228 ether
Error: Error: Error: Transaction ran out of gas. Please provide more gas:
@gnidan In my opinion you can close this issue. I think there is nothing to change in truffle code to fix it.
Oh! Thanks for your time for this issue, dont know why i missed that extra config. I was going crazy. @robertmagier