Token standards & NFTs

ERC-1155

ERC-1155 is one smart contract that can manage many different kinds of token at once. Think of a video game: a single shop contract might hold a million identical gold coins, ten thousand identical health potions, and a handful of unique legendary swords. ERC-20 would need a separate contract for each item type and ERC-721 a separate contract for the swords; ERC-1155 puts all of them under one roof, each distinguished only by a numeric token id.

Mechanically, balances live in a nested mapping from token id to owner to amount. A token id whose total supply is one behaves like a non-fungible token; a token id with a large supply behaves like a fungible token, so the same standard covers both. The signature functions are balanceOf(account, id), balanceOfBatch for many at once, safeTransferFrom(from, to, id, amount, data), and safeBatchTransferFrom, which moves several different ids in a single atomic transaction. That batching is the headline efficiency win: minting or transferring a hundred item types costs far less gas than a hundred separate ERC-20 or ERC-721 calls.

Metadata follows a URI convention where the contract returns one template string containing the substring {id}; clients replace it with the token id encoded as a lowercase hexadecimal number padded to 64 characters. ERC-1155 also mandates the safe-transfer receiver hook: if the recipient is a contract it must implement onERC1155Received (or the batch variant) and return the correct magic value, otherwise the transfer reverts, preventing tokens from being stranded in contracts that cannot handle them. The standard originated at Enjin and is widely used by games and marketplaces.

function safeBatchTransferFrom(
  address from, address to,
  uint256[] calldata ids,
  uint256[] calldata amounts,
  bytes calldata data
) external;

ERC-1155 is not 'NFTs only' nor 'fungible only' — fungibility is a per-id property decided by how many of each id you mint, which is exactly why it suits games and editions.

Also called
multi-token standard多代幣標準