solidity - 在测试网上使用 Remix 部署合约时出现问题
问题描述
我尝试使用 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 Mainnet 中部署它时,一切正常,没有错误。有什么建议么?
这是相关代码
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);
}
// ...
}
我在这里上传了整个代码,因为它太长了。
解决方案
IUniswapV2Router02 _uniswapV2Router =
IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
// Create a Pancakeswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
构造函数中的这些行试图与主网上存在的合约进行交互。但是你在测试网上,这个地址没有合约。
如本文所述,Pancake 测试网路由器地址为:
因此,您需要将硬编码地址替换为该地址。
推荐阅读
- angular - Angular - 使用来自外部“资产”的翻译
- excel - Excel 公式:如何通过列名引用单元格
- c# - 如何在 VSCode 中为 nuget 包配置本地提要?
- python-3.x - python将字符串转换为三个块,如果不是两个块
- sql-server - SQL 函数 SYSDATETIME() 可以返回重复值吗?
- reactjs - 'npm run dev' vs 'next build' tsx 代码编译限制不同级别
- excel - 如何在excel中创建动态超链接?
- html - 创建相对于其自身宽度的响应式 html 元素
- mysql - 如何将表及其数据从一个数据库复制到另一个数据库?
- firebase - 有没有办法通过提供服务帐户凭据在一个函数中访问两个 Firestore 项目?