gpt4 book ai didi

solidity - 在测试网上使用 Remix 部署合约时出现问题

转载 作者:行者123 更新时间:2023-12-04 16:24:44 38 4
gpt4 key购买 nike

我尝试使用 Remix 将合约部署到测试网(所有测试网都返回相同的消息),但出现此错误:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { "code": -32000, "message": "gas required exceeds allowance (30000000) or always failing transaction" }

但是当我尝试在 BSC 主网中部署它时,一切正常,没有错误。有什么建议吗?

这是相关代码

contract artemis is Context, IERC20, Ownable {
// ...

constructor() public {
_rOwned[_msgSender()] = _rTotal;

IUniswapV2Router02 _uniswapV2Router =
IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
// Create a Pancakeswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());

// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;

//exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;

emit Transfer(address(0), _msgSender(), _tTotal);
}

// ...
}

我在这里上传整个代码,因为它太长了。

code

最佳答案

IUniswapV2Router02 _uniswapV2Router =
IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);

// Create a Pancakeswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());

您的构造函数中的这些行试图与 exists 的合约进行交互。在主网上。但是你在测试网上,那里有 no contract在这个地址上。

this post 中所述,Pancake 测试网路由器地址为:

0xD99D1c33F9fC3444f8101754aBC46c52416550D1

所以你需要把硬编码的地址换成这个。

关于solidity - 在测试网上使用 Remix 部署合约时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67260766/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com