ERC-721 and ERC-1155
Suggest an editAn ERC-20 contract stores a balance per address, so it has no way to say "Alice owns this specific token and Bob owns that one." ERC-721 stores an owner per token id. ERC-1155 stores a balance per id and holder, and the other two are special cases of it.
ERC-20 stores how many, not which one
ERC-20's storage model is one mapping, mapping(address => uint256): address to balance. That's enough to represent fungible value, where every unit of the token is interchangeable. If Alice has 500 USDC and sends 100 to Bob, her balance goes to 400 and Bob's goes up by 100. The contract doesn't need to know which 100 units moved because they're identical.
This breaks the moment you want tokens to be individually addressable. A Uniswap V3 liquidity position is one example. Each position has its own price range, so two positions in the same pool are not interchangeable, and V3 issues every position as an ERC-721 token (the Uniswap V3 lesson covers them). A digital painting or a land parcel in a virtual world is another. You can't represent them as balance amounts because the question isn't "how many" but "which one."
ERC-721: one id, one owner
ERC-721 inverts the mapping. Each token has a unique 256-bit ID, and the contract stores mapping(uint256 => address), the address that owns each ID.
When Alice mints token 42, the contract sets ownerOf(42) = alice. When she transfers it to Bob, the contract sets ownerOf(42) = bob. There's never a question of "how much of token 42" because there's exactly one of token 42 by construction.
The core of the standard's interface:
interface IERC721 {
function balanceOf(address owner) external view returns (uint256);
function ownerOf(uint256 tokenId) external view returns (address);
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool approved) external;
}The mapping goes from id to owner, so the contract can answer "who owns token 42" but not "what tokens does Alice own?" balanceOf exists, but it returns a count of how many tokens this address owns rather than the IDs themselves. The optional ERC721Enumerable extension adds the list, but it costs storage gas on every mint and transfer to maintain the index.
tokenURI(tokenId) returns a URI pointing at the token's metadata. The metadata is typically a JSON document at that URI, hosted off-chain or on IPFS. ERC-721's convention is one URI per token. That gives you per-token flexibility but means most production contracts implement a base URI plus a tokenId suffix to avoid storing thousands of strings on chain.
approve and setApprovalForAll are the two delegation mechanisms. approve(spender, tokenId) lets one address transfer one specific token. setApprovalForAll(operator, true) lets one address transfer any token the owner holds. Marketplaces use the second form because they need to list any of your tokens for sale.
ERC-1155: many ids, balances per holder
Take a game with gold pieces, swords, and potions. Gold is fungible, so it needs an ERC-20 contract. A unique sword needs an ERC-721 contract. A potion that exists in 50 identical units is awkward in both. As an ERC-721 it becomes 50 separate ids for 50 interchangeable items, and as an ERC-20 every potion type needs a contract of its own. Moving a player's inventory to another address then takes a separate transaction for each of those contracts and for each unique item.
ERC-1155 keeps both dimensions in one mapping, mapping(uint256 => mapping(address => uint256)). Each tokenId has its own balance mapping, and one contract can hold many tokenIds. The storage layout looks like a two-dimensional table: id by holder, with the cell value being how many of that id this holder owns.
When you mint 1,000,000 of token 1 to Alice, the contract sets balances[1][alice] = 1000000. When you mint 1 of token 42 to her, it sets balances[42][alice] = 1. Both ids live in the same contract and follow the same storage shape, so the game doesn't need three contracts. The standard was also designed from the start with batch operations in mind: you can transfer twenty ids worth of inventory from one address to another in one transaction.
The core of its interface:
interface IERC1155 {
function balanceOf(address account, uint256 id) external view returns (uint256);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
function setApprovalForAll(address operator, bool approved) external;
}balanceOf takes both an account and an id. It returns the holder's balance of that specific id. As with ERC-721, there's no method that returns a list of all ids the holder has. The standard expects clients to discover ids off-chain through the TransferSingle and TransferBatch event logs.
The uri(id) function returns a URI for the token's metadata, similar to ERC-721's tokenURI. The returned string can contain the literal substring {id}, which wallets, marketplaces, and indexers replace with the token id in lowercase hex, padded to 64 characters, before fetching, so a metadata server of your own has to accept ids in that form. This lets one URI template serve all ids in the contract.
ERC-1155 has no name() or symbol(), because a single contract might hold many unrelated token types. OpenZeppelin's ERC1155 also doesn't track total supply per id unless you include the ERC1155Supply extension.
ERC-20 and ERC-721 are special cases of ERC-1155
ERC-20 stores balances per holder, with no concept of token identity. ERC-721 stores an owner per id, with no concept of quantity. ERC-1155 stores both, a balance per (id, holder) pair. The first two are special cases of the third.
The other side of this is gas cost. ERC-721's mapping is shallower, so reads and writes are slightly cheaper than ERC-1155's nested mapping. The difference is small, but for high-frequency operations it can add up. ERC-1155 trades that small per-write cost for the structural benefits of batch operations.
ERC-1155 is sometimes described as supporting fungible, non-fungible, and semi-fungible tokens. The contract doesn't enforce any of the three. The label follows from how many of each id you mint.
A tokenId with a supply in the millions, spread across many holders, behaves like a fungible token. That is GOLD in the table. SWORD_OF_DAWN has a supply of one and is non-fungible, because only one address can hold it at a time. POTION_LE has a supply of 50 and is semi-fungible: the 50 units are interchangeable within their id but distinct from other ids. The contract has no idea which category an id falls into. It stores balances[id][holder] for all of them, and the same code path that moves your gold can move your sword.
One batch transaction moves many ids
ERC-1155 ships with safeBatchTransferFrom, which ERC-721 doesn't have, and the OpenZeppelin implementation adds _mintBatch and _burnBatch internal functions. All three take arrays of ids and amounts and process them in a single transaction.
Every Ethereum transaction has a base cost of 21,000 gas, regardless of what it does. On top of that you pay for whatever the transaction's code consumes. If you're transferring three NFTs from Alice to Bob using ERC-721, you pay 21,000 base gas three times, 63,000 in total, plus the per-transfer execution cost. With ERC-1155's batch transfer, you pay the base cost once. The batch of three saves 42,000 gas of base cost, and every further token in the batch saves another 21,000.
A batch is also atomic. With three separate ERC-721 transfers, any one could revert independently. The first two might succeed and the third might fail, leaving you in a half-applied state. ERC-1155's batch is one transaction, so either all the transfers happen or none do. A bundle of game items needs that, because partial fulfillment would corrupt the user's inventory.
What safe transfers and operator approvals cost
Both standards have a safeTransferFrom variant that calls a hook on the receiving contract. ERC-721 calls onERC721Received, and ERC-1155 calls onERC1155Received or onERC1155BatchReceived. If the recipient is a contract that doesn't implement the right hook, the transfer reverts. That prevents tokens from being trapped in contracts that have no logic to handle them.
The hook is an external call. During the transfer the token contract runs the recipient's code, and that code can call back into the contract that started the transfer. If your contract makes a safe transfer before it has finished updating its own state, it has the bug from the reentrancy lesson. The defenses are the same: update state before the call, and add a reentrancy guard.
setApprovalForAll is the same trade as the unlimited allowance in the ERC-20 lesson. The operator can move every token the owner holds in that contract at any time, so a vulnerability in the operator contract, or an approval given to the wrong address, loses all of them. ERC-721 lets you narrow the grant to one token with approve. ERC-1155 has only setApprovalForAll, so revoking access from a single item means revoking the entire operator's authority.
Picking between them
You want ERC-721 when each token has its own identity and the project is one collection of similar but distinct items, such as a PFP project, a 1-of-1 art piece, or a registry of named items. The per-id metadata is the point. You also want it when on-chain enumeration of "what does this address own" matters, since the ERC721Enumerable extension gives you that.
You want ERC-1155 when you have multiple token types from the start, or when batch operations are part of the design. That covers game inventories with currencies, weapons, and consumables, event ticketing where different tiers are different ids but tickets within a tier are interchangeable, airdrops where you'll be doing many transfers at once, and multi-asset marketplaces where one contract needs to handle a long tail of token types.
Some projects use both: a flagship ERC-721 collection for the headline assets, with an ERC-1155 alongside for accessories, consumables, or fractional editions.
The choice is rarely about gas alone. For a small collection with infrequent transfers, the savings from ERC-1155's batch operations don't matter. If you're unsure, sketch the storage layout in pseudocode before picking the standard, and ask which sentence describes your tokens: "a registry of unique items" or "balances across many item types."