如何解决无法在 BSC Scan 上验证和发布合同
我正在尝试在 BSC Scan 测试网上验证和发布合同。 我正在使用 Open Zepellin 和 Remix - ETH IDE,但是出现以下错误:
如果我尝试在 Etherscan 上验证它,我相信同样的问题是真实的。
我做错了什么?
这是我贴在 BSC Scan 上验证并发布的代码。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Presidente is ERC20,Ownable {
constructor() ERC20("Presidente","PRES") {
_mint(msg.sender,1000000 * 10 ** decimals());
}
function mint(address to,uint256 amount) public onlyOwner {
_mint(to,amount);
}
}
这是我得到的完整错误
解决方法
我看到您正在尝试验证,而您的合同需要展平,
这是你需要做的:
-
转到 remix.ethereum.org 并创建一个新文件 token.sol
-
复制/粘贴您的代码并保存
-
转到最后一个标签插件管理器并寻找FLATTENER安装
-
FLATTENER 将显示为一个标签,点击它并按下 Flatten token.sol
-
按另存为 token_flat.sol
-
返回第一个选项卡,您将找到新文件
-
删除所有显示为“// SPDX-License-Identifier: MIT”的额外许可证
-
移动第二部分成为他们的部分
pragma solidity ^0.8.0;
/**
-
@dev 来自 ERC20 标准的可选元数据函数的接口。
-
自 v4.1 起可用。 / 接口 IERC20Metadata 是 IERC20 { /*
- @dev 返回令牌的名称。 */ function name() 外部视图返回(字符串内存);
/**
- @dev 返回令牌的符号。 */ function symbol() 外部视图返回(字符串内存);
/**
- @dev 返回令牌的小数位。 */ 函数小数()外部视图返回(uint8); }
// 文件:@openzeppelin/contracts/token/ERC20/IERC20.sol
-
在这部分之后
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient,uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner,address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender,uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,address recipient,uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from,address indexed to,uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner,address indexed spender,uint256 value);
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
- 编译,你会很高兴
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。