1

I've recently been running into issues with contract deployment (receiving "Error: VM Exception while processing transaction: out of gas" during migration). It's been my understanding that the deployment cost of a contract is directly related to the size of the contract bytecode. I'm using Truffle and in my 2_deploy_contracts.js file I've been logging contract bytecode size in an attempt to investigate:

const Contract1 = artifacts.require("Contract1");
const Contract2 = artifacts.require("Contract2");
const Contract3 = artifacts.require("Contract3");

async function doDeploy(deployer, network) {
    console.log("Contract1 bytecode size: ", Contract1.deployedBytecode.length);
    console.log("Contract2 bytecode size: ", Contract2.deployedBytecode.length);
    console.log("Contract3 bytecode size: ", Contract3.deployedBytecode.length);

    await deployer.deploy(Contract1);
    await deployer.deploy(Contract2);
    await deployer.deploy(Contract3);
}

module.exports = function(deployer, network) {
    deployer.then(async () => {
        await doDeploy(deployer, network);
    });
};

The results of these logs show that the contract which I know to be causing the problem has a deployedBytecode size of only 24078 bytes, while the others (which are not causing issues) have sizes approaching 40000 bytes. I don't understand why its not the largest bytecode contract causing the out of gas error. Is my understanding of deployment costs incorrect?

(FYI this example has been simplified and the actual situation includes far more than 3 contracts. The contract causing issues also uses a couple different libraries... could this contribute to the problem?)

  • Are libraries linked to your contract? If the constructor generates an error it might cause an out of gas exception (even if your contract is really small). You should check error conditions on the contract's constructor. – Ismael Jul 28 '18 at 1:22

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.