【问题标题】:Not able to verify and publish contract on BSC Scan无法在 BSCScan 上验证和发布合同
【发布时间】:2021-07-22 18:59:08
【问题描述】:

我正在尝试在 BSC Scan 测试网上验证和发布合同。 我正在使用 Open Zepellin 和 Remix - ETH IDE,但是我收到以下错误:

未找到:不支持文件导入回调

如果我尝试在 Etherscan 上进行验证,我相信同样的问题是正确的。

我做错了什么?

Contract Link

这是我粘贴在 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);
    }
}

这是我得到的完整错误

【问题讨论】:

  • 我也有同样的问题。

标签: ethereum solidity etherscan binance-smart-chain binance-chain


【解决方案1】:

我看到您正在尝试验证,而您的合同需要展平,

这是你需要做的:

  1. 转到 remix.ethereum.org 并创建一个新文件 token.sol

  2. 复制/粘贴您的代码并保存

  3. 转到最后一个选项卡插件管理器并查找 FLATTENER 安装它

  4. FLATTENER 将显示为一个标签,点击它并按下 Flatten token.sol

  5. 按另存为 token_flat.sol

  6. 回到第一个标签,你会发现新文件

  7. 删除所有显示的额外许可证 "// SPDX-License-Identifier: MIT"

  8. 移动第二部分成为他们的部分

    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
  1. 编译,一切顺利

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2021-08-13
    • 2021-08-14
    • 2012-08-07
    • 1970-01-01
    相关资源
    最近更新 更多