I tried to use truffle connected to Ganache to deploy my contract which imports two other contracts but does not initialise any of these two imported contracts upon deployment. Truffle kept on reporting the error "out of gas". But no matter how high the attached gas is (also adjusted the ganache chain gas limit and truffle.js gas parameter to allow higher transaction gas), I always get the same error: out of gas.
In reality the contract deployment should never consume that much gas. I used Remix to deploy the same contract locally and to Rinkeby using MetaMask, both were successful. Gas consumed was very standard, nothing shockingly high.
Since the contracts are not open to the public, I cannot share all the contracts. But once I include these two functions(at the same time) in the contract that I was trying to deploy, then I get the error "out of gas" no matter how high I set the gas with the deployment transaction.
`function createUser(address AccountOwner, string userID, string firstName, string secondName, string userAddress, string _email, string phone) public isRegulator() isCSD() returns (address){
User newUser = new User(Regulator, address(this), AccountOwner, userID, firstName, secondName, userAddress, _email, phone);
users.push(address(newUser));
userCreated(address(newUser), firstName, secondName);
return address(newUser);
}
function createEntity(string entityID, address entityOwner, string entityName, string entityCode, string entityAddress, string _email, string phone) public isRegulator() isCSD() returns (address){
Entity newEntity = new Entity(Regulator, entityOwner, entityID, entityName, entityCode, entityAddress, _email, phone);
entities.push(address(newEntity));
entityCreated(address(newEntity), entityName);
return address(newEntity);
}
`
Deployment successful. The transaction gas used returned by Remix(connected to Rinkeby) is 5063223.
Below is the error message from truffle:
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0xce7de0a325c8c6cd468b9bec9daa242e99717640fd92761be05aea16266a3c1f
Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network...
... 0xbe2cbb3a4052d4f92fd103fb9e872fd7582a8df57389ef3d227673db09c2d52b
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying CSD...
... 0x3dbe830b07915f92ffdc1b5267588f01a0c7dcb52674ed9a2f54f7df03c381f5
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: VM Exception while processing transaction: out of gas
at Object.module.exports.InvalidResponse (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:225:1
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:134:1
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
gas limit in ganache: 1000000020
truffle.js gas parameter value: 9000000(also have used larger values, still same error)
truffle version): v4.1.14node --version): v6.3.1npm --version): 3.10.3I had the same problem and this solved my issue.
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545, // ganache-cli
//port: 7545, // ganache ui
network_id: "*" // Match any network id
}
},
solc: {
optimizer: {
enabled: true,
runs: 200
}
}
};
truffle compile --all
truffle migrate --reset
I also upgraded to the latest beta version of truffle as it has a much nicer output and debugging enhancements, etc. You don't have to do this but just in case you want to.
npm uninstall -g truffle
npm install -g truffle@beta
I hope this helps!
@rsamo Thanks Ryan! I had the same problem and that fixed it.
Glad I could help @roschler!
@rsamo That really helps, thank you!
Seems like this is not a problem anymore. Closing for issue maintenance! Thanks everyone!
FYI I just had the same problem and your suggestion @one70six fixed it. I got it down to a single, innocuous line in my solidity code where if it was commented out the contract deployed, but if I uncommented it it said OOG (even though I have ganache set to 10b gas). But, fixed now, fortunately.
Most helpful comment
I had the same problem and this solved my issue.
I also upgraded to the latest beta version of truffle as it has a much nicer output and debugging enhancements, etc. You don't have to do this but just in case you want to.
I hope this helps!