繁体   English   中英

尝试编译 Solidity 令牌合约但不断收到编译错误

[英]Trying to compile solidity token contract but keep getting compile error

我不断收到此编译器错误:

CompileError: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol:61:41: ParserError: Expected '{' but got reserved keyword 'override'
    function name() public view virtual override returns (string memory) {
                                        ^------^

这是我的合同代码:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
    
    contract TestToken is Standard, DetailedERC20 {

        uint256 public totalSupply;

        constructor(string _name, string _symbol, uint8 _decimals) 
            DetailedERC20(_name, _symbol, _decimals) 
            public 
            {

            }
}

这是ERC20合约代码:

contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The defaut value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

我开始工作了,确保 Solidity 编译器是最新的! 我的 Solidity 编译器是 0.8.6 版,我在 truffle 配置文件中列出的编译器是 0.5.16

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM