Creating our Token Discussion

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

yeah thats very strange dunno why its 0 .ill clone your code and have a look tomorrow its late here now

Hello @Konzaih

I will suggest by using the ā€˜.send({from: address[0]})ā€™ function instead of the ā€˜.call()ā€™ when minting considering your altering a state in the smart contract.

With kind regards

hi i have a problem on compiling please help me

Hello @josejalapeno,

You are using what the version of:

  • Truffle
  • npm
  • Node.js

I used v14.18.0, may work for you. Try reinstalling Node.js (then try also initializing the directory again with npm init and install needed dependencies again)

Hope this is helpful to you
With kind regards

hello @alp257

my node verson is16.13.1

my truffle i install the 5.0.1

my npm is 7.24.1

what should i do step by step to downgrade my node?

1 Like

What you can try first is running ā€˜npm cache clean --forceā€™ (just to make sure no data corruption was there even if it only happens rarely) then see if the problem still exists.

Next, instead of ā€˜downgradingā€™, I suggest uninstalling Node.js and npm then installing them again afterwards.

With kind regards

1 Like

if you want to switch node i sugges using node version manager this way you can download an duse any version of node you want and switch between them. heres their github for installation read the docs

https://github.com/nvm-sh/nvm

I did do a little reading on that error too few ansers on SO said its most likley compatability with node and trufle. but yur version of node is fine v14 is what i use. i suggest removing truffle completely and starting again maybe something happened during instialltion thats causing this

1 Like

Seems like youā€™ve suddenly been flooded by advice!! :sweat_smile:

Hereā€™s a link to an FAQ which might also be helpful. Hopefully, something will do the trick :smiley:

1 Like

@josejalapeno In case you havenā€™t seen this ā€¦

1 Like

yes i also install the nvm yesterday and did some youtube around it, i can swap to the old node, but then npm doesnt work, which means i cant install truffle without npm, without truffle i cannot develop and compile the codes.

If you canā€™t get npm working when using the Node Version Manager then I would suggest uninstalling everything again and re-installing Node.js from the link in these instructions I posted yesterdayā€¦

It will take you to all of the downloads for previous versions of Node.js, and Iā€™m pretty sure that these files will install both Node.js and npm together. Thatā€™s correct isnā€™t it @mcgrane5 @thecil @alp257 ?

The instructions in this FAQ will also explain how to uninstall correctly.

1 Like

It could also be that the installation went wrong, you could try to uninstall the version from nvm, then install it again, keep in mind that you should do all of this as administrator.

Let us know how it goes for you, i recently install v16 and was able to npm install truffle without any issue.

Carlos Z

3 Likes

@Jon sorry for late reply. But yeah i strange the way nvm didnt work. I would suggest following @thecil 's advice and unistalling node and trying again. i also agree i dont think it should be the node version because im running 14. something and its fine. it could be the truffle install didnt work correctly. so try redo everything again from scratch.

Simply deleteing node or unistalling it inst enough if your gonna do it you should uninstall it and delete any roaming data in app/roamingdata on your machine. could look up a tutorial on how to do this. let us know how you get on we will get this fixed for you

2 Likes

@josejalapeno In case you havenā€™t seen this latest advice for you ā€¦

1 Like

Hi Iā€™m having troubles downloading the linter package.
Installing ā€œ[email protected]ā€ failed.Hide outputā€¦

npm ERR! code E500
npm ERR! 500 Internal Server Error - GET https://www.atom.io/api/packages/linter-solidity/versions/0.7.1/tarball

I donā€™t understand why I keep getting this error for any package I try to download and would appreciate help.

1 Like