Last updated on November 8th, 2024 at 01:46 pm
Here’s a quick breakdown of the core interfaces of each of these token standards, with the key functions you’ll often encounter when working with them:
- ERC20 – Fungible Tokens
ERC20 tokens are fungible, meaning each token is identical and has the same value as any other token in the contract. They’re used widely for currencies, points, and other identical asset types.
Key Interface Functions:
• totalSupply(): Returns the total supply of tokens.
• balanceOf(address account): Returns the balance of tokens for a specific address.
• transfer(address recipient, uint256 amount): Transfers tokens to another address.
• approve(address spender, uint256 amount): Allows an address to withdraw a certain number of tokens on behalf of the token owner.
• allowance(address owner, address spender): Shows the remaining number of tokens that a spender is allowed to withdraw from an owner’s balance.
• transferFrom(address sender, address recipient, uint256 amount): Transfers tokens from one address to another based on allowances.
These functions form the base for most tokens you see in use today, like stablecoins or other fungible assets.
- ERC721 – Non-Fungible Tokens (NFTs)
ERC721 tokens are non-fungible, meaning each token is unique. This standard is widely used for digital assets like art, collectibles, or real estate.
Key Interface Functions:
• balanceOf(address owner): Returns the number of NFTs held by a particular address.
• ownerOf(uint256 tokenId): Returns the owner of a specific NFT by tokenId.
• safeTransferFrom(address from, address to, uint256 tokenId): Transfers a specific NFT from one address to another safely (ensures contract receivers can handle the NFT).
• transferFrom(address from, address to, uint256 tokenId): Transfers ownership of a specific NFT.
• approve(address approved, uint256 tokenId): Approves another address to transfer the specified NFT on behalf of the owner.
• getApproved(uint256 tokenId): Returns the address approved for a specific NFT.
• setApprovalForAll(address operator, bool approved): Approves or removes an operator to manage all the NFTs for a particular owner.
• isApprovedForAll(address owner, address operator): Checks if an operator is approved for all NFTs of an owner.
These functions allow unique assets to be tracked and transferred on the blockchain, enabling use cases like art marketplaces, virtual real estate, and collectibles.
- ERC1155 – Multi-Token Standard
ERC1155 is a multi-token standard that supports both fungible and non-fungible tokens within a single contract. It’s efficient for use cases where you need both token types (e.g., a game with currencies and unique items).
Key Interface Functions:
• balanceOf(address account, uint256 id): Returns the balance of tokens of type id owned by an account.
• balanceOfBatch(address[] accounts, uint256[] ids): Returns the balances of multiple accounts and token types in a single call.
• safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data): Transfers a specific amount of a specific token type from one address to another.
• safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data): Transfers multiple types and amounts of tokens in a single call.
• setApprovalForAll(address operator, bool approved): Approves or disapproves an operator to manage all tokens of the caller.
• isApprovedForAll(address account, address operator): Checks if an operator has approval to manage all tokens of a given account.
ERC1155’s flexibility makes it especially popular in gaming and digital collectibles, where you might have different items (like weapons, potions) and also need in-game currency in the same contract.
These standards provide the fundamental building blocks for tokens on the Ethereum blockchain.
The Ethereum token standards, ERC20, ERC721, and ERC1155, were developed by different authors within the Ethereum community. Each of these standards was proposed as an Ethereum Improvement Proposal (EIP) and received contributions from various developers. Here’s a brief history of their origins and primary authors:
-
ERC20
• Author: Fabian Vogelsteller with contributions from Vitalik Buterin. • Published: November 2015. • Purpose: To create a standard interface for fungible tokens, allowing them to interact seamlessly across different applications and exchanges. • Background: ERC20 emerged as the first widely adopted token standard, setting a foundation for a vast ecosystem of fungible tokens, including stablecoins and other assets.
-
ERC721
• Primary Authors: Dieter Shirley (initial proposer) with contributions from William Entriken, Jacob Evans, and Natassia Sachs. • Published: January 2018. • Purpose: To standardize the interface for non-fungible tokens (NFTs), enabling the ownership and transfer of unique assets on the blockchain. • Background: ERC721 laid the groundwork for the NFT ecosystem, used in applications like digital art, collectibles, and gaming. It was inspired by the need for unique tokens and gained significant attention with the rise of projects like CryptoKitties.
-
ERC1155
• Primary Author: Witek Radomski (co-founder and CTO of Enjin), with contributions from Andrew Cooke, Philippe Castonguay, James Therien, and Eric Binet. • Published: June 2018. • Purpose: To introduce a multi-token standard that supports both fungible and non-fungible tokens within a single smart contract. • Background: ERC1155 was created to address limitations of ERC20 and ERC721, particularly for gaming and digital collectibles. It allows for more efficient management and transfer of tokens, especially in applications where different token types coexist.
Each of these standards contributed significantly to Ethereum’s flexibility and growth, enabling developers to build sophisticated applications that leverage fungible and non-fungible assets.
