所需天然气超过限额(8000000)

发布于 2025-01-09 07:06:08 字数 1950 浏览 4 评论 0原文

我的智能合约通常在本地 ganache 和公共测试网络上在 bsc 中运行, 但是在自己搭建的私链中,总是提示gas required超出限额(8000000)。我完全找不到解决问题的方法。帮帮我

源代码:

IERC20 diamond;

function upgradePre(
        uint256 recordNo,
        uint256 tokenType,
        uint256 tokenId,
        uint256 expireTime,
        uint256 diamondquantity
    ) public payable {
        //is it timed out
        require(expireTime >= block.timestamp, "request expired");
        //Check for duplicate submissions
        require(!orders[recordNo].isCompletePre, "repeat transaction");
        //Ownership of the token
        require(
            msg.sender == _getOwnerByTokenIdAndTokenType(tokenId, tokenType),
            "owner exception"
        );
        //token's current level
        uint256 currentLevel = _getLevelByTokenIdAndTokenType(
            tokenId,
            tokenType
        );

        UpgradeConfItem memory upgradeConfItem = _getUpradeConf(tokenId, tokenType, currentLevel + 1);
        //start transfer
        require(upgradeConfItem.diamondquantity > 0 && diamondquantity >= upgradeConfItem.diamondquantity, "diamondquantity too small");
        require(
            diamond.balanceOf(msg.sender) >= diamondquantity,
            "Insufficient balance"
        );
        require(
            (diamond.allowance(msg.sender, address(this)) >= (diamondquantity)),
            "0xSUB: Allowance required"
        );
        require(
            diamond.transferFrom(msg.sender, receiveAddress, diamondquantity),
            "payment failed"
        );

        //init upgrade order
        _initUpgradeOrder(recordNo, tokenId, tokenType, currentLevel);
        //request random number
        logService.requestRandomNum(1, recordNo);
        //print biz log
        _logUpgradePre(
            recordNo,
            tokenId,
            tokenType,
            diamondquantity,
            currentLevel
        );
    }

My smart contract runs in bsc normally on local ganache and the public test network,
but in the private chain built by myself, it always prompts gas required exceeds allowance (8000000).I can not find the solution to solve the problem at all.help me

Source code:

IERC20 diamond;

function upgradePre(
        uint256 recordNo,
        uint256 tokenType,
        uint256 tokenId,
        uint256 expireTime,
        uint256 diamondquantity
    ) public payable {
        //is it timed out
        require(expireTime >= block.timestamp, "request expired");
        //Check for duplicate submissions
        require(!orders[recordNo].isCompletePre, "repeat transaction");
        //Ownership of the token
        require(
            msg.sender == _getOwnerByTokenIdAndTokenType(tokenId, tokenType),
            "owner exception"
        );
        //token's current level
        uint256 currentLevel = _getLevelByTokenIdAndTokenType(
            tokenId,
            tokenType
        );

        UpgradeConfItem memory upgradeConfItem = _getUpradeConf(tokenId, tokenType, currentLevel + 1);
        //start transfer
        require(upgradeConfItem.diamondquantity > 0 && diamondquantity >= upgradeConfItem.diamondquantity, "diamondquantity too small");
        require(
            diamond.balanceOf(msg.sender) >= diamondquantity,
            "Insufficient balance"
        );
        require(
            (diamond.allowance(msg.sender, address(this)) >= (diamondquantity)),
            "0xSUB: Allowance required"
        );
        require(
            diamond.transferFrom(msg.sender, receiveAddress, diamondquantity),
            "payment failed"
        );

        //init upgrade order
        _initUpgradeOrder(recordNo, tokenId, tokenType, currentLevel);
        //request random number
        logService.requestRandomNum(1, recordNo);
        //print biz log
        _logUpgradePre(
            recordNo,
            tokenId,
            tokenType,
            diamondquantity,
            currentLevel
        );
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒时光 2025-01-16 07:06:08

我遇到这个问题是因为网络问题。

只需更改为另一台具有更好网络的服务器(或者哪个网络未被 rpc 服务器阻止)

I met this problem because network problem.

just change to another server which has better network ( or which network is not blocked from rpc server)

此刻的回忆 2025-01-16 07:06:08

至此在 BSC 和 Ganache 中成功运行。然后请检查您的钱包中是否有足够的私链原生代币。

As this run successfully in BSC and Ganache. Then please check whether you have enough native token of your private chain in the wallet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文