10. ERC20s

EIPs

  • Stands for Ethereum Improvement Proposals

  • These are ideas to improve L1 technology

  • eips.ethereum.org holds all improvement proposals


ERCs

  • Stands for Ethereum Request for Comments

  • ERC & EIP share same number

    • ERC-20 (EIP-20)

    • It also means it is the 20th proposal


ERC-20

  • Token deployed on ethereum chains which follows ERC-20 token standard

  • Tether, chainlink (ERC-677), unitoken, dai are examples of ERC-20 tokens


Creating ERC-20 Token

Manual

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

contract ManualToken {
    uint256 initialSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    // Transfer Tokens
    // Subtract "from address" amount and add "to address" amount

    function transfer(address from, address to, uint256 amount) public {
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
    }

    /** Send _value tokens to _to on behalf of _from
     *
     * @param _from The address of sender
     * @param _to The address of the recipient
     * @param _value The amount to send
     *
     */
    function transferFrom(
        address _from,
        address _to,
        uint256 _value
    ) public returns (bool) {
        require(_value <= allowance[_from][msg.sender]);
        allowance[_from][msg.sender] -= _value;
        transfer(_from, _to, _value);
        return true;
    }

    // Other Functions
}

OpenZeppelin

  • Take boilerplate code from OpenZeppelin

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

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

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MT") {
        _mint(msg.sender, initialSupply);
    }
}

Last updated