Skip to content

Challenge 01

Creating and manipulating fungible tokens (ERC20).

Task

  1. use openzeppelin's implementation of ERC20 to create a fungible token called "Sollearn Demo" and with a symbol of "SLD".

  2. increase your balance to 100 of the newly created token.

  3. deploy the contract

  4. send 10 tokens to a random address.

Info

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

Hint

Check OpenZeppelin implementation

Hint

Check the _mint() function in OpenZeppelin implementation

Hint

Check the decimals() function.

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 SollearnCoin is ERC20 {

    constructor() ERC20("Sollearn Demo", "SLD"){
        // mint uses the smallest unit
        uint oneUnit = 10 ** decimals(); // the default value of decimals() is 18
        uint amount = 100 * oneUnit; // 100_000_000_000_000_000_000
        address to = msg.sender;
        // mint will create new tokens and transfer them to the deployer
        _mint(to, amount);
    }

    // or in one line
    // constructor() ERC20("Sollearn Demo", "SLD"){ _mint(msg.sender, 100 * 10 ** decimals()); }

}
3. call the transfer(address _to, uint256 _value) method with the following parameters: (to: 0x0011223344556677889900112233445566778899, amount: 10000000000000000000)

Warning

You are required to multiply by 10^(decimals()) in your code and when interacting with etherscan.

10000000000000000000 (10 + 18 zero) = 10 RC

When you use a wallet, you specify the amount as 10.

References

EIP-20: Token Standard