简体   繁体   中英

Why am I getting exceeds gas limit error when I specify the exact gas limit?

I am deploying a contract using truffle, and when I specify the gas limit as the gas I want to use for the transaction I always get the exceeds gas limit error. Why does this happen?

edit What I am trying to do is deploy the crypto kitties KittyCore.sol contract to my local devnet. I am using truffle to deploy it.

From another page, How to deploy truffle contract to dev network when using inheritance? , I found that since there is a contract hierarchy, I need to deploy my contracts in order. I used this technique, and I am able to deploy 4 out of 7 contracts, with the fifth, KittyAuction, giving the following error: The contract code couldn't be stored, please check your gas amount

Posted below is my truffle deployer script

var KittyCore = artifacts.require("KittyCore");
var KittyMinting = artifacts.require("KittyMinting");
var KittyAuction = artifacts.require("KittyAuction");
var KittyBreeding = artifacts.require("KittyBreeding");
var KittyOwnership = artifacts.require("KittyOwnership");
var KittyBase = artifacts.require("KittyBase");
var KittyAccessControl = artifacts.require("KittyAccessControl");
var SaleClockAuction = artifacts.require("SaleClockAuction");

module.exports = function (deployer) {
    deployer.deploy(KittyAccessControl).then(function () {
        return deployer.deploy(KittyBase).then(function () {
            return deployer.deploy(KittyOwnership).then(function () {
                return deployer.deploy(KittyBreeding).then(function () {
                    return deployer.deploy(KittyAuction, {
                        gas: 400000
                    }).then(function () {
                        return deployer.deploy(KittyMinting).then(function () {
                            return deployer.deploy(KittyCore);
                        })
                    })
                })
            })
        })
    });
};

My gas limit is set to 18000000000. This gas number is produced by running the following function on the actual contract that fails to deploy

var gasPrice;
KittyAuction.web3.eth.getGasPrice(function (error, result) {
    gasPrice = Number(result);
    console.log(gasPrice);
})

I have been fiddling with this number and nothing seems to work.

So I was able to deploy it. What I did was reset my blockchain, and set gasLimit to 0x8000000 and gave each contract that was troublesome a gas value of 0x7000000, and it deployed. Funny thing though, it wouldnt deploy again. I guess the gasLimit adjusted after a few blocks were mined because I got an error saying I was over the limit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM