Q&A-3How do ERC-20, ERC-721, and ERC-1155 differ in their storage layout, gas efficiency during batch transfers, and representation of semi-fungible tokens?
Answer
ERC-20, ERC-721, and ERC-1155 organize EVM storage differently, which directly shapes their transaction overhead and suitability for multi-item interactions.
1. Storage Layout and State Representation
-
ERC-20 (Single Fungible Asset): Tracks scalar balances and operator allowances for a single implicit asset.
SOLIDITYmapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances;Every asset instance requires a separate contract deployment, adding runtime context-switching and storage lookup costs across distinct contracts.
-
ERC-721 (Non-Fungible Tokens): Tracks discrete token IDs to exclusive owners and addresses per-token approval alongside global operator status.
SOLIDITYmapping(uint256 => address) private _owners; // tokenId => owner mapping(address => uint256) private _balances; // owner => count mapping(uint256 => address) private _tokenApprovals; // tokenId => approved operator mapping(address => mapping(address => bool)) private _operatorApprovals;Tracking individual token ownership forces $O(N)$ storage writes on multi-token transfers and clears individual approvals on transfer.
-
ERC-1155 (Multi-Token Standard): Nests asset identity (
id) within balance mappings, managing fungible, non-fungible, and semi-fungible balances under one contract.SOLIDITYmapping(uint256 => mapping(address => uint256)) private _balances; // id => account => balance mapping(address => mapping(address => bool)) private _operatorApprovals;Approvals are purely operator-based (
setApprovalForAll), eliminating per-token approval storage slots.
2. Gas Efficiency in Batch Operations
Transferring $N$ distinct items demonstrates significant divergence:
| Dimension | ERC-20 (Multi-Asset) | ERC-721 | ERC-1155 |
|---|---|---|---|
| Transaction Boundaries | $N$ external calls to $N$ contracts | 1 contract, $N$ internal loops or distinct external calls | 1 native batch call (safeBatchTransferFrom) |
| Call Overhead | $N \times 2,600$ cold account access | 1 cold call + internal loops | 1 cold call + calldata decoding |
| Approval Checks | $N$ allowance storage reads/updates | $N$ token or operator checks | 1 single operator check upfront |
| Receiver Hook Execution | Optional (ERC-1363) or none | $N$ calls to onERC721Received | 1 single call to onERC1155BatchReceived |
| Log Emissions | $N$ distinct Transfer events across contracts | $N$ Transfer events | 1 TransferBatch event emitting array parameters |
For a transfer of 5 distinct items to a contract receiver:
- ERC-721: Requires 5 balance decrements, 5 balance increments, 5 owner updates, and 5 separate external calls to
onERC721Received(costing at least 2,600 gas per cold address call plus execution). - ERC-1155: Requires 1 operator check, 5 balance slot updates, 1
TransferBatchlog, and exactly 1 external call toonERC1155BatchReceived.
3. Semi-Fungible Token Representation
A semi-fungible token (SFT) behaves like a fungible batch during initial lifecycle stages (e.g., general-admission tickets with supply > 1) and can transition into a non-fungible item upon consumption (e.g., redeemed stub with distinct seat assignment).
- ERC-20: Cannot represent discrete SFT states within one contract; it lacks per-item IDs.
- ERC-721: Cannot natively model fungibility. Modeling 50 identical concert tickets forces minting 50 unique token IDs, consuming 50
_ownersstorage slots. - ERC-1155: Native SFT implementation. An
idcan hold a supply of $K$ units (_balances[id][user] = 50). When redeemed, a protocol burns units from the fungibleidand mints a specific non-fungibleid(where total supply is enforced as 1, often encoded with split bit-fields in theuint256 id: e.g., upper 128 bits for collection/type, lower 128 bits for unique sequence).
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.