【问题标题】:Solidity ParserError: Expected ';' but got 'is'Solidity ParserError:预期的';'但得到了“是”
【发布时间】:2021-08-20 02:11:06
【问题描述】:

我一直在学习 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: 应为 ';'但得到了'是'--> GToken.sol:7:21: | 7 |合约 GToken 为 ERC20 { | ^^

【问题讨论】:

    标签: blockchain solidity erc20


    【解决方案1】:

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

    • 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
        }
    }
    

    【讨论】:

    • 感谢您解决了这个问题。
    猜你喜欢
    • 2022-08-12
    • 1970-01-01
    • 2022-12-11
    • 2022-07-24
    • 2021-12-11
    • 2016-02-13
    • 2019-01-10
    • 1970-01-01
    • 2020-08-01
    相关资源
    最近更新 更多