Back to Course

Session 6.1 - Ethereum Tokens

Apply Ethereum token standards and protocols

Module 6 45 minutes

Learning Objectives

  • Understand Ethereum token standards and their applications
  • Implement ERC-20, ERC-721, and ERC-1155 token contracts
  • Analyze token economics and utility models
  • Explore advanced token features and extensions
  • Evaluate token security considerations and best practices

Token Standards Overview

Ethereum Token Ecosystem

Ethereum token standards define common interfaces and behaviors that enable interoperability between different tokens and applications.

Fungible Tokens

Identical, interchangeable units

Non-Fungible Tokens

Unique, individual assets

Multi-Token Standards

Hybrid fungible/non-fungible

ERC-20: Fungible Token Standard

The Foundation of DeFi

ERC-20 is the most widely adopted token standard, forming the backbone of the DeFi ecosystem.

pragma solidity ^0.8.0;

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract MyToken is IERC20 {
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    
    uint256 private _totalSupply;
    string public name;
    string public symbol;
    uint8 public decimals;
    
    constructor(string memory _name, string memory _symbol, uint256 _totalSupply) {
        name = _name;
        symbol = _symbol;
        decimals = 18;
        _totalSupply = _totalSupply * 10**decimals;
        _balances[msg.sender] = _totalSupply;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }
    
    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }
    
    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }
    
    function transfer(address to, uint256 amount) public override returns (bool) {
        require(to != address(0), "Transfer to zero address");
        require(_balances[msg.sender] >= amount, "Insufficient balance");
        
        _balances[msg.sender] -= amount;
        _balances[to] += amount;
        emit Transfer(msg.sender, to, amount);
        return true;
    }
    
    function approve(address spender, uint256 amount) public override returns (bool) {
        _allowances[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }
    
    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }
    
    function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
        require(to != address(0), "Transfer to zero address");
        require(_balances[from] >= amount, "Insufficient balance");
        require(_allowances[from][msg.sender] >= amount, "Insufficient allowance");
        
        _balances[from] -= amount;
        _balances[to] += amount;
        _allowances[from][msg.sender] -= amount;
        
        emit Transfer(from, to, amount);
        return true;
    }
}

ERC-721: Non-Fungible Token Standard

Unique Digital Assets

ERC-721 enables the creation of unique, non-interchangeable tokens representing individual assets or collectibles.

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721, Ownable {
    uint256 private _tokenIdCounter;
    mapping(uint256 => string) private _tokenURIs;
    
    constructor() ERC721("MyNFT", "MNFT") {}
    
    function mint(address to, string memory tokenURI) public onlyOwner {
        uint256 tokenId = _tokenIdCounter;
        _tokenIdCounter++;
        
        _mint(to, tokenId);
        _setTokenURI(tokenId, tokenURI);
    }
    
    function _setTokenURI(uint256 tokenId, string memory tokenURI) internal {
        require(_exists(tokenId), "Token does not exist");
        _tokenURIs[tokenId] = tokenURI;
    }
    
    function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "Token does not exist");
        return _tokenURIs[tokenId];
    }
    
    function burn(uint256 tokenId) public {
        require(_isApprovedOrOwner(msg.sender, tokenId), "Not approved or owner");
        _burn(tokenId);
        delete _tokenURIs[tokenId];
    }
}

ERC-1155: Multi-Token Standard

Hybrid Token System

ERC-1155 allows a single contract to manage multiple token types, both fungible and non-fungible.

Feature ERC-20 ERC-721 ERC-1155
Token Types Fungible only Non-fungible only Both fungible and non-fungible
Contract Efficiency One token per contract One collection per contract Multiple types per contract
Batch Operations No Limited Yes, built-in
Gas Efficiency Standard High for single transfers Optimized for batch operations
Use Cases Currencies, utility tokens Art, collectibles, identity Gaming, complex ecosystems

Token Economics Models

Tokenomics Design

Token economics define how tokens create value, incentivize behavior, and sustain ecosystem growth.

Utility Tokens
  • Access Rights: Platform usage permissions
  • Fee Payment: Transaction and service fees
  • Governance: Voting and decision-making
  • Staking: Network security participation
  • Examples: BNB, LINK, UNI
Value Accrual Models
  • Burn Mechanisms: Deflationary pressure
  • Revenue Sharing: Profit distribution
  • Buyback Programs: Market support
  • Staking Rewards: Yield generation
  • Network Effects: Usage-driven value

Advanced Token Features

Extended Functionality

Modern token implementations include advanced features for enhanced functionality and user experience.

Pausable Tokens
  • Emergency stop functionality
  • Admin-controlled pausing
  • Security incident response
  • Upgrade preparation
Burnable Tokens
  • Token supply reduction
  • Deflationary mechanisms
  • Value accrual strategies
  • Ecosystem sustainability
Vesting Tokens
  • Time-locked releases
  • Team and investor vesting
  • Gradual token distribution
  • Market stability

Security Considerations

Token Security Best Practices

Token contracts require careful security considerations to prevent vulnerabilities and protect user funds.

Common Vulnerabilities
  • Integer Overflow/Underflow: Arithmetic errors
  • Reentrancy Attacks: Recursive calls
  • Access Control Issues: Unauthorized operations
  • Front-running: Transaction ordering attacks
  • Flash Loan Attacks: Price manipulation
  • Approval Race Conditions: Double spending
Security Measures
  • SafeMath Libraries: Overflow protection
  • Reentrancy Guards: State lock mechanisms
  • Role-Based Access: Permission systems
  • Time Locks: Delayed execution
  • Multi-signature: Distributed control
  • Formal Verification: Mathematical proofs

Token Launch Strategies

Go-to-Market Approaches

Different token launch strategies serve various project goals and community building objectives.

Strategy Description Advantages Considerations
Fair Launch No pre-mine, equal opportunity Community trust, decentralization No initial funding, slower development
ICO/IEO Initial token sale to public Fundraising, community building Regulatory compliance, market risk
Airdrop Free token distribution User acquisition, network effects Sybil attacks, value dilution
Liquidity Mining Rewards for providing liquidity Bootstrap liquidity, user engagement Mercenary capital, sustainability
Bonding Curves Algorithmic price discovery Continuous liquidity, price stability Complex mechanics, front-running

Ethereum Community and Subreddit

Community-Driven Development

The Ethereum community, particularly through platforms like Reddit's r/ethereum, plays a crucial role in token development, governance, and ecosystem growth.

Community Platforms
  • r/ethereum: Main discussion forum for protocol updates
  • r/ethdev: Developer-focused discussions and tutorials
  • r/ethtrader: Trading and market analysis
  • r/ethfinance: Financial applications and DeFi
  • Discord/Telegram: Real-time community chat
  • GitHub: Code repositories and EIP discussions
Community Contributions
  • EIP Proposals: Ethereum Improvement Proposals
  • Token Standards: Community-driven standards development
  • Code Reviews: Peer review of smart contracts
  • Educational Content: Tutorials and documentation
  • Bug Reports: Security vulnerability disclosure
  • Tool Development: Developer tools and libraries

Advanced Token Analysis

Token Metrics and Analytics

Understanding token performance requires comprehensive analysis of on-chain metrics and community engagement.

Metric Category Key Indicators Tools/Platforms Insights
On-Chain Metrics Transfer volume, holder count, transaction frequency Etherscan, Dune Analytics, Nansen Token utility and adoption patterns
DeFi Integration Liquidity pools, yield farming, lending protocols DeFiPulse, DeBank, Zapper Token's role in DeFi ecosystem
Governance Activity Proposal participation, voting turnout Snapshot, Tally, Boardroom Community engagement and decentralization
Social Sentiment Reddit mentions, Twitter activity, GitHub commits LunarCrush, CryptoPanic, GitHub Community health and development activity

Summary

Key Takeaways
  • Ethereum token standards provide interoperability and common interfaces for different token types
  • ERC-20 dominates fungible tokens, ERC-721 enables unique assets, and ERC-1155 offers hybrid functionality
  • Token economics design is crucial for creating sustainable value and incentive alignment
  • Advanced features like pausing, burning, and vesting enhance token functionality
  • Security considerations are paramount in token contract development
  • Launch strategies should align with project goals and regulatory requirements
  • Community platforms like Ethereum subreddit drive ecosystem development and governance
  • Comprehensive token analysis requires both on-chain metrics and social sentiment tracking
  • Token standards continue evolving to meet new use cases and improve efficiency

What's Next?

Next, we'll explore Augur & Golem Case Studies to analyze decentralized application architectures.