【问题标题】:Why am I getting exceeds gas limit error when I specify the exact gas limit?当我指定确切的气体限制时,为什么会出现超出气体限制的错误?
【发布时间】:2018-11-02 20:14:53
【问题描述】:

我正在使用 truffle 部署合约,当我将 gas limit 指定为我想用于交易的 gas 时,我总是会收到超出 gas limit 的错误。为什么会这样?

编辑 我想要做的是将加密小猫 KittyCore.sol 合约部署到我的本地 devnet。我正在使用松露来部署它。

从另一个页面How to deploy truffle contract to dev network when using inheritance?,我发现由于有一个合约层次结构,我需要按顺序部署我的合约。我使用了这种技术,我能够部署 7 个合约中的 4 个,其中第五个是 KittyAuction,出现以下错误:无法存储合约代码,请检查您的 gas 量

下面发布的是我的松露部署脚本

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);
                        })
                    })
                })
            })
        })
    });
};

我的gas limit设置为18000000000。这个gas数是通过在实际部署失败的合约上运行以下函数产生的

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

我一直在摆弄这个数字,但似乎没有任何效果。

【问题讨论】:

  • 你可以设置的最小gas限制是多少,并且交易仍然成功?
  • 另外,编辑您的问题以包括您的合同代码、您指定的 gas 限制以及您是如何得出该数字的。
  • 我正在尝试将 cryptokitties 主合约部署到我的本地 devnet。有很多引用要发布,但它是免费提供的,除了将支付关键字添加到构造函数之外,我没有做任何更改

标签: ethereum solidity truffle


【解决方案1】:

所以我能够部署它。我所做的是重置我的区块链,并将 gasLimit 设置为 0x8000000,并为每个麻烦的合约赋予 0x7000000 的 gas 值,然后部署。有趣的是,它不会再次部署。我猜想在开采几个区块后调整 gasLimit,因为我收到一个错误,说我超出了限制

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 2021-07-19
    • 2022-11-14
    • 2021-08-04
    相关资源
    最近更新 更多