0

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 { | ^^

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
Tarxan
  • 3
  • 2

1 Answers1

0

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
    }
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100