繁体   English   中英

Solidity ParserError:预期的';' 但得到了“是”

[英]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:预期的';' 但得到了'是'--> GToken.sol:7:21: | 7 | 合约 GToken 为 ERC20 { | ^^

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

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

然后你会遇到uint(decimals)的类型转换错误。 当您查看远程合同时,您会看到 decimals ()是一个视图 function - 不是属性。 因此,您应该像调用 function: 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
    }
}

暂无
暂无

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

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