Apply Ethereum token standards and protocols
Ethereum token standards define common interfaces and behaviors that enable interoperability between different tokens and applications.
Identical, interchangeable units
Unique, individual assets
Hybrid fungible/non-fungible
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 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 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 define how tokens create value, incentivize behavior, and sustain ecosystem growth.
Modern token implementations include advanced features for enhanced functionality and user experience.
Token contracts require careful security considerations to prevent vulnerabilities and protect user funds.
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 |
The Ethereum community, particularly through platforms like Reddit's r/ethereum, plays a crucial role in token development, governance, and ecosystem growth.
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 |
Next, we'll explore Augur & Golem Case Studies to analyze decentralized application architectures.