Truffle Box Tutorial Token on Git Hub Error

:computer: Environment

:memo:Details

:1234: Code to reproduce

The token is not linked and I can’t access it on metta mask lastly nothing happens when I transfer the token. Note that I am using windows 10 please help! IDK It could be Ganache also.TutorialToken - Wallet - Google Chrome 10_22_2020 2_29_17 AM|690x367

1 Like

Hi @herschell,

Unfortunately the Truffle TutorialToken is outdated so may take some effort to get working.
I mostly used https://www.trufflesuite.com/tutorials/robust-smart-contracts-with-openzeppelin with some additions.

You could look at the following tutorials:


I installed the current version of OpenZeppelin Contracts (openzeppelin-solidity is the old package name)

npm install @openzeppelin/contracts

I created a simple Tutorial Token contract

// contracts/TutorialToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;

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

contract TutorialToken is ERC20 {

    constructor () public ERC20("TutorialToken", "TT") {
        _setupDecimals(2);
        _mint(msg.sender, 120 * (10 ** uint256(decimals())));
    }
}

I had to update Migrations.sol to a current version

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;

contract Migrations {
  address public owner = msg.sender;
  uint public last_completed_migration;

  modifier restricted() {
    require(
      msg.sender == owner,
      "This function is restricted to the contract's owner"
    );
    _;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }
}

I used ganache-cli as my local blockchain network (though you could use Ganache).

I updated my truffle config to use ganache-cli (port 8545) and a later Solidity version 0.6.12.

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*" // Match any network id
    }
  },
  compilers: {
    solc: {
      version: "0.6.12",      // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    },
  },
};

In app.js I changed the port of the local blockchain to 8545.

      App.web3Provider = new Web3.providers.HttpProvider('http://127.0.0.1:8545');

I used the Truffle Console to transfer tokens to a test account I already had setup on MetaMask, though if you import the private key of the account that deploys the contract you won’t need to do this.

$ npx truffle console
truffle(development)> token = await TutorialToken.deployed()
undefined
truffle(development)> await token.transfer('0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0', 200)
{ tx: ...
truffle(development)> (await token.balanceOf('0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0')).toString()
'200'

The app then displayed my token balance and I could transfer tokens to other accounts.

Feel free to ask any questions so I can help you get up and running.

Hi @herschell,

I wanted to check if you were able to get it up and running?