# ERC-1155 Primer **Published by:** [0xNelli](https://paragraph.com/@0xnelli/) **Published on:** 2024-11-14 **URL:** https://paragraph.com/@0xnelli/erc-1155-primer ## Content OverviewThe ERC-1155 standard specifies an interface that supports multiple tokens governed by a single contract. Additionally, tokens controlled by the contract can have different types of fungibility. Supported fungibility types include:Fungible (ERC-20 like)Semi-fungibleNon-fungible (ERC-721 like)It also introduces a number of QoL features, such as bulk approvals, where one approval applies to all token types held by the contract. This removes the need for users to approve an individual token each time they transact with it. Moreover, it introduces batched transactions. As the contract supports multiple tokens, it provides a mechanism to query balances for multiple tokens in one transaction or to transfer multiple token types in one transaction. Finally, it also implements safe transfers to ensure that the receiving entity supports the ERC-1155 token type.Semi FungibilityThis fungibility type refers to a token that possesses unique metadata and properties but can be held by multiple addresses. For example, a game may require a key to gain access to a specific level or hidden content. The token representing the key is unique and would have metadata and properties related to the content it unlocks. However, many users of the game may hold the token. This type of token has characteristics of both an ERC-20 and ERC-721. It represents a unique asset with its own properties and metadata, like an ERC-721. However, these tokens have multiple owners and are interchangeable with one another, as they represent the same asset, much like an ERC-20.Batch OperationsBatch operations introduce significant gas savings as they permit multiple balance queries or transfers to be completed in a single transaction. This is only possible as the ERC-1155 standard maintains the state of multiple tokens in a single contract. Batch Query Balance: Queries an array of addresses (accounts) for the balance they hold of the token type id. Returns an array of token balances in the order of the accounts provided to the function call.balanceOfBatch(address[] accounts, uint256[] ids) -> uint256[] The length of accounts must equal the length of idsYou can query multiple addresses for the balance of different tokens the contract holdsE.g. query two addresses the balance of gold(fungible), potions(semi-fungible) and unique swords(non-fungible) the each own all in one transactionBatch Transfer: You can transfer multiple different types of tokens from one address to another in the same transaction.safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data); ids and amounts must have the same lengthto must implement onERC1155BatchReceivedOpenZeppelin extended batch functionality:OpenZeppelin extended the batch features included in the ERC-1155 standard, introducing a mintBatch and a burnBatch. Mint Batch: Mint multiple tokens in one transaction. The mint can also include multiple types of tokens, e.g. mint ERC-20 and ERC-721 tokens to the same address in a single transaction._mintBatch(address to, uint256[] ids, uint256[] values, bytes data); ids and values must have the same lengthto cannot be the zero addressThe to address must implement onERC1155BatchReceivedBurn Batch: Burn multiple tokens in a single transaction._burnBatch(address from, uint256[] ids, uint256[] values); from cannot be the zero addressfrom must have at least the amount of tokens specified in the values parameter of the token represented by the array positionids and values must have the same lengthSupply ExtensionThis is an additional extension that can be used to track the total supply of each of the tokens in the ERC-1155 contract. The only balance related functionality enshrined in the ERC-1155 standard is the balanceOf and balanceOfBatch functions, that only reveal information about the tokens an address holds. This extension adds the following functions:totalSupply(id) which returns the total amount of tokens with the id id.totalSupply() which returns the number of tokens the ERC1155 contract holds.exists(id) returns a bool as to whether the token of id existsSourceshttps://eips.ethereum.org/EIPS/eip-1155https://ethereum.org/en/developers/docs/standards/tokens/erc-1155/https://docs.openzeppelin.com/contracts/5.x/erc1155https://docs.openzeppelin.com/contracts/5.x/api/token/erc1155#ERC1155 ## Publication Information - [0xNelli](https://paragraph.com/@0xnelli/): Publication homepage - [All Posts](https://paragraph.com/@0xnelli/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@0xnelli): Subscribe to updates - [Twitter](https://twitter.com/0xNelli): Follow on Twitter