Creating our Token Discussion

what does th error message say post a screenshot. try usuing sol 0.8 or somethung.

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

Hi,
Could anybody please help me solving this error?
I am at Deploying our Token section. I successfully run truffle develop , but when trying to compile, receive the error: TypeError: Error parsing C:/Users/Olga/SimpleGame/Solidity/contracts/GameToken.sol: Cannot read properties of undefined (reading 'addFunction')

1 Like

hey @OlgaB seems like a typo in your contract. can you share your GameToken.sol file

1 Like

hey @mcgrane5 thank you for such a fast reply :slight_smile:
here is what I wrote in the file:

pragma solidity 0.5.0

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";

contract GameToken is ERC20, ERC20Detailed {

  constructor (string memory _name, string memory _symbol, uint8 _decimals)
  ERC20Detailed (_name, _symbol, _decimals)
  public
  {}


    function mint(address to, uint256 value) public returns (bool) {
        _mint(to, value);
        return true;
    }

}
2 Likes

Hey @OlgaB, hope you are well.

Please share your code in the following way so we can review it properly :nerd_face:

Carlos Z

1 Like

Maybe useful for anyone taking the course in 2021 and in the future, and haven’t took the Ethereum Smart Contract Programming 201 course (which used a newer version of Openzeppelin) before this one.

  • You can use Visual Studio Code as an editor instead of Atom (depends on your preference), you have to download the Solidity plugin

  • use ‘npm install @openzeppelin/contracts’ to install the latest version of Openzeppellin

  • Here’s the code I used for the contract, stuff in ‘ERC20Detailed.sol’ mentioned in the video lecture is already included in ‘ERC20.sol’ if you ran the npm command mentioned above:

pragma solidity ^0.8.0;

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

contract GameToken is ERC20 {

    constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) public {}

    function mint(address to, uint256 amount) public virtual {
        _mint(to, amount);
    }
}

hey Olga. Yes i think your problem isyour using new openzeppelin librsary but the one from the video is older erc20Detailed is depricated. just remove the import

1 Like

@mcgrane5 Thank you for help :slight_smile:
Removing the import was only the first step - because I still received errors.
Took a look at what other folks of the academy are doing and I also renewed the versions.
Ran npm install @ openzeppelin /contracts AND ```
npm install -g truffle

Now it works!
1 Like

brillant hats great to hear all the best with the rest of the course. be sure to post if you run into any issues

Hello @mcgrane5 @thecil

I hope you can help me as I am stuck.
If I work with openzeppelin 2.5.0 my Tokens do not mint and the mint call returns “true”
really dont understand why it wouldn’t mint.

same happens if I install the newest Version

After reading mcgrane5’s tipps I’ve switched to version 2.3 but now I can not compile as the file Context.sol is missing.

1 Like

@Konzaih can you share the code. I would recommend going back to version 2.4 or whatever your previous version was so you dont have to ad the context file. can you share your code. its been ages since ive done this course so share your git repo and ill have a look

Hello @mcgrane5 yeah just wanted to add it after switching to another version, but you’re quick :smiley:
currently I am on v2.1.1 as Filip in his video. Again the “True” result when trying to mint.

Github: https://github.com/EdiBes/EthereumJS_Game.git

GameToken.sol

pragma solidity ^0.5.0;

import "/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";


contract GameToken is ERC20, ERC20Detailed {

  constructor(string memory _name, string memory _symbol, uint8 _decimals)
  ERC20Detailed(_name, _symbol, _decimals)
  public
  {}

  function mint(address account, uint256 value) public returns (bool) {
      _mint(account, value);
      return true;
  }
}

ERC20.sol Mint function

function _mint(address account, uint256 value) internal {
        require(account != address(0));

        _totalSupply = _totalSupply.add(value);
        _balances[account] = _balances[account].add(value);
        emit Transfer(address(0), account, value);
    }

Thanks for your help!

1 Like

before i try to clone what is the error you get when you try to call the mint function

There is no actual Error
The console prints: “true”

1 Like

Hello Konzaih,
Checking the github link you provided, if that is the current code you are using, that means you have the latter version of the game code in this course which removes the minting of the token and focuses on the marketplace (ERC1155 token integration). Either you take a previous version or you add the token minting code in eth.js and the function call in index.html.
Similar to this:

async function mintAfterGame(nrOfTokens) {
    // ethereum.request({ method: 'eth_accounts' }) // imho, more appropriate for Metamask usage, returns an array, first index = selected address
    web3.eth.getAccounts().then(listOfAddress => {
      // 'mint' is the function call in the Token contract
      contractTokenErc20.methods.mint(listOfAddress[0], nrOfTokens).send({from: listOfAddress[0]})
      .on('receipt', receipt => {
        alert("Transaction Complete");
      });
    });
}
...
      function updateTimeLeft() {

        if(gameOver) {

          if(!coinsMinted) {
            mintAfterGame(score);
            coinsMinted = true;
          }

          return;
        }
...

With kind regards

Hey alp

Tbh I can’t quite follow you.
I’ve followed the course structure and downloaded the complete code as a reference but didn’t use it.
My Game code is in GameDevelopment\EthereumGame and my Contracts in GameDevelopment\Solidity. The Folder FinalCode is copied from Github.
Just seen now that there’s suddenly an eth.js file that wasn’t introduced.
Have not connected the Game to the Blockchain yet, still just trying to interact with the contract.

Thanks for your answer!

I see, my bad. I misunderstood.

Trying to recall how I get past that part, I used a more updated version of the token standard (with Openzeppelin) where the separate ‘ERC20Detailed’ .sol file is no longer used. This was the code I used:

pragma solidity ^0.8.0;

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

contract GameToken is ERC20 {

    constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) public {}

    function mint(address to, uint256 amount) public virtual {
        _mint(to, amount);
    }
}
const GameToken = artifacts.require("GameToken");

module.exports = function (deployer) {
  deployer.deploy(GameToken, "Game Token", "GT");
};

Just a heads up, if you get to continue to connect the game and the smart contract later on:
The ‘missing’ video is not in the right sequence. One should watch ‘ Configuring Web.js ’ first which is found on Page 5 Section The Business Case for Decentralized Gaming then back to Page 3 Section Integrating ERC20 Token with the Game with ‘ Redeploying & Configuring our Contract ’.

Hope the information is helpful.
With kind regards

2 Likes

@Konzaih ok so your code is working then. the reason this returns true os because you have your mint function set to return true if the transaction is a success. As for thr reason that total supply is zero well this is the total supply of the token not the balance. When you mint your are effectively minting or giving tokens to the specified address. To check if the mint was successful use the balances function on the account you minted to it should return whatever you minted. as for the reason the total supply is zero thats a strange one. i can check this but i cannot find the solidity contracts in that repo are they deffo up?

There is something majorly wrong in this regard because the toal supply for the erc20 contract (well in the latest versions) is set to 10 ** 18. so that result should be 10 ** 18. However you are interacting with the contracts in a way i would not usually do. So i am going to ask you to try this alternative method and see if things work so that the total supply is 10 ** 18

//1 deploy
truffle migrate --reset
//2 make an instance of gametoken
let game = await GameToken.deployed()
//3 get total supply
let totalSupply = await game.totalSupply()
game.toString() //reurns the bn in string format nice way to look at BN's

the result should be 1 and 18 zeros

2 Likes

@alp257 @mcgrane5

Thanks for the help you two, really appreciate it.
I failed the Github upload, now I’ve included the contracts, sorry for that.

@alp257 thanks for the heads up with Web.js &
I will try your approach tomorrow.

@mcgrane5
I’ve checked with the balance function but again got 0.
Not entirely sure if I executed your approach correctly but here is a look at the console

1 Like