What is an ERC-1155?
In this article lets see what is ERC -1155?
A smart contract multi-token standard for:
-fungible tokens (ERC-20)
-NFTs (ERC-721)
ERC-721 v.s. ERC-1155
ERC-721 tokens are good at identifying one type of object.
For example, balances are based on the entire contract for all tokenId values:
- Solidity
balanceOf(address)
ERC-1155 tokens are good at identifying multiple objects.
For example, balances are isolated based on unique tokenId values:
- Solidity
balanceOf(address, tokenId)
Vending Machine Analogy
ERC-721:
-Example: Water Bottles
-Each tokenId represents a unique water bottle brand
ERC-1155:
-Example: Vending Machine Items
-Each tokenId can be a different vending machine item:
-water bottles
-snack bars
-tea
-trail mix
ERC-1155 Batch Transfer
You can bulk transfer ERC-1155 tokens based on tokenId and quantity by calling:
- Solidity
safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data)
What do ERC-721 and ERC-1155 Contracts have in Common?
OpenZeppelin contracts:
ERC721Holder.sol
and
ERC1155Holder.sol
are safety inheritance contracts. A contract must inherit these contracts to accept tokens being transferred to them.
However, ERC-20 tokens do not have a safety inheritance holder contract.
When transferring tokens to contracts, call smart contract functions that have “transferFrom()” behavior. It is recommended to only send tokens directly to a contract on test networks, otherwise, you risk accidentally burning your tokens.