Challenge 02
Creating and manipulating fungible tokens (ERC20).
Task
-
use openzeppelin's implementation of ERC20 to create a fungible token called "USDC".
-
override the function
decimals()
and make it return 2 as the dollar. -
give yourself 93 USDC.
-
transfer 6 USDC to 0x0011223344556677889900112233445566778899.
Solution
- open remix-ide
- 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;
}
}
transfer(address _to, uint256 _value)
method with the following parameters: (to: 0x0011223344556677889900112233445566778899
, amount: 600
)