Compilation Error

Hello everyone I get this Compilation error
I guess I make a mistake in the constructor ?
Can someone get some hints please ?

token.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import '../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol';


contract GameToken is ERC20  {
    constructor () ERC20(string memory name_, string memory symbol_) {
        _mint(msg.sender, 10000);
    }
}

with :
2_token_migration.js

const GameToken = artifacts.require("GameToken");

module.exports = function (deployer) {
  deployer.deploy(GameToken,"GameTK","GTK");
};

I get this error msg below :

ParserError: Expected ‘,’ but got ‘memory’
–> project:/contracts/token.sol:7:33:
|
7 | constructor () ERC20(string memory name_, string memory symbol_) {
| ^^^^^^

Compilation failed. See above.

  • Fetching solc version list from solc-bin. Attempt #1
  • Fetching solc version list from solc-bin. Attempt #1

Compilation is all Ok if I use

constructor () ERC20(“GameTK”,“GTK”) {
and
deployer.deploy(GameToken);

Probably the same error that I had to troubleshoot yesterday, try modifying your how you pass your arguments in the migration script like this (with the single quotes):

module.exports = function (deployer) {
  deployer.deploy(GameToken, 'GameTK', 'GTK');
};

Hello @alp257
Thanks for your feedback
Unfortunately it doesn t work

Truffle compilation fails and point string memory name as the prb in the constructor
I don t get it yet =)

Hey @Sieg, hope you are well.

I think the problem comes from the constructor arguments, although the token name and symbol will be used for the ERC20 contructor, you also have to point this 2 variables as argument for the constructor, and then pass them to the ERC20.

Example:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import '../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol';


contract GameToken is ERC20  {
   constructor (string memory name_, string memory symbol_) ERC20(name_, symbol_) {
       _mint(msg.sender, 10000);
   }
}/

Let me know if it helps! :nerd_face:

Carlos Z

This is my contract and migration, which works for me - edited with your token name.

token.sol

// SPDX-License-Identifier: UNLICENSED

import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

pragma solidity ^0.8.0;

contract GameToken is ERC20 {

    constructor() ERC20("GameToken", "GTK"){
        _mint(msg.sender, 10000);
    }
}

#_gametoken_migration.js

const GameToken = artifacts.require("GameToken");

module.exports = async function (deployer, network, accounts) {
  await deployer.deploy(GameToken);
};

The network & accounts keywords are not necessary, but if you are building your dex they will be needed for the migration to work properly in the Truffle development environment.

1 Like

Thanks for the update. I’ll be sure to keep an eye on this thread.