Skip to content

Challenge 02

Creating and manipulating fungible tokens (ERC20).

Task

  1. use openzeppelin's implementation of ERC20 to create a fungible token called "USDC".

  2. override the function decimals() and make it return 2 as the dollar.

  3. give yourself 93 USDC.

  4. transfer 6 USDC to 0x0011223344556677889900112233445566778899.

Info

You can use remix-ide or hardhat or truffle to create the contract and deploy it.

Solution
  1. open remix-ide
  2. create a new file and add the following code:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

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

contract USDC is ERC20 {

    constructor() ERC20("USDC", "USDC"){
        // mint uses the smallest unit
        uint oneUnit = 10 ** decimals();
        // amount is 9300 cent (93.00 USDC)
        uint amount = 93 * oneUnit;
        address to = msg.sender;
        // mint will create new tokens and transfer them to the deployer
        _mint(to, amount);

        // or in one line
        //_mint(msg.sender, 93 * 10 ** decimals());
    }

    function decimals() public override(ERC20) pure returns (uint8){
        return 2;
    }
}
3. call the transfer(address _to, uint256 _value) method with the following parameters: (to: 0x0011223344556677889900112233445566778899, amount: 600)

References

EIP-20: Token Standard