简体   繁体   中英

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

I've been learning solidity, however, I am still very new. Currently I am making a ERC20 Token but I am having some difficulties with doing so. Here is what I have.

// 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));
        
}

The Error I recieve when trying to compile the contract is as follows:

ParserError: Expected ';' but got 'is' --> GToken.sol:7:21: | 7 | Contract GToken is ERC20 { | ^^

You have two syntax errors in your code:

  • contract should be lowercase, not Contract
  • constructor is missing closing brace }

Then you're going to run into a type conversion error with the uint(decimals) . When you look at the remote contract, you see that decimals() is a view function - not a property. So you should read its value as if you were calling a function: decimals() .


Combined all together:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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