我不断收到此编译器错误:
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;
}
答案 0 :(得分:0)
我开始工作了,它确保了 Solidity 编译器是最新的!我的 Solidity 编译器是 0.8.6 版,我在 truffle 配置文件中列出的编译器是 0.5.16