Solidity ParserError: Expected ';' but got 'is'

Solidity ParserError: Expected ';' but got 'is'

我一直在学习solidity,但是,我还是很新。目前我正在制作一个 ERC20 令牌,但我在这样做时遇到了一些困难。这是我的。

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";

Contract GToken is ERC20 {
    constructor(string memory name, string memory symbol)
        ERC20("GToken", "GTKN") public {
            _mint(msg.sender, 1000000 * 10 ** uint(decimals));
        
}

我在尝试编译合约时收到的错误如下:

ParserError: 应为“;”但得到 'is' --> GToken.sol:7:21: | 7 |合约GToken为ERC20 { | ^^

您的代码中有两个语法错误:

  • contract应该是小写的,不是Contract
  • constructor 缺少右大括号 }

那么您将 运行 与 uint(decimals) 发生类型转换错误。当您查看远程合约时,您会看到 decimals() 是一个视图函数 - 而不是 属性。所以你应该像调用函数一样读取它的值:decimals().


全部加在一起:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
// removed the IERC20 import, not needed in this context

contract GToken is ERC20 {
    constructor(string memory name, string memory symbol) ERC20("GToken", "GTKN") public {
        _mint(msg.sender, 1000000 * 10 ** decimals()); // calling the `decimals()` function
    }
}