所需天然气超过限额(8000000)
我的智能合约通常在本地 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到这个问题是因为网络问题。
只需更改为另一台具有更好网络的服务器(或者哪个网络未被 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)
至此在 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.