Quick Links:
- ERC 1155 @ Openzeppelin Docs: https://docs.openzeppelin.com/contracts/3.x/ERC1155
- Morali.io - A faster way to develop dapps
- tldr; This youtube guy is from Morali.io
- ERC721 vs. ERC1155 by EatTheBlocks: Click here
Source@youtube: Click here
With ERC721, we can have only one type of nfts. For e.g., say if we need to create tokens for the seats of a concert, and later on we need to create tokens for another concert then we would need to deploy another smart contract for that. BUT with ERC1155, we can have multiple types of nfts within the same contract. And we don't need to define the types of nfts we need in future at the time of contract deployment. Instead we can define it anytime later. And we can define hundreds or thousands of nfts where we can have special ids and owners for each one of those type of nfts. ERC1155 can deal with much larger set of features than erc721. The drawback with ERC1155 is that it becomes more complicated.
Source@youtube: Click here
ERC1155 is an improvement over ERC721 and ERC20 token standard.
How its different from ERC721?
-
With this, we can manage multiple token types in the same contract. So the problem with ERC721 is that say we one nft contract that deals with cryptoKitty, but then we have cryptoCuties nfts that need to have another contract. If you were using ERC1155 contract, you can create of both these nft types using same contract. And that means it will take less space on blockchain. This ERC1155 token standard was created to make contracts which were more functional and consume less space on blockchain. And since if we have one contract and it can manage different types of token types, thats a huge win and thats what we do with ERC1155. With this contract, we not only can manage multiple types of tokens but we can have fungible tokens and semi-fungible tokens as well. For e.g., we have a game where we can collect gold and other items like swords/achievements/special_items/customized_helmet. So gold will be need to fungible token and sword/achievements/special_items/customized_helmet need to benon-fungible tokens.
-
We can do batch transfers with ERC1155 and that was another thing that was brocken with 721 becoz with 721 standard we would need to make same number of txns as many nft's need to be transferred. And that can take a lot of block space on blockchain and it would take a lot of gas fees. So with ERC1155 there is batch transfer, we can make use of this feature to transfer multiple nfts to multiple parties in single txn. So ERC1155 allows nft creators to allow people to create new tokens without them having to deploy new contracts over and over again. So this is very very powerful stuff. ERC1155 is the standard to build nft and tokens today. Also, there's a very little reason to use ERC721 token standard unless you want want that's a little bit more simple and easy to understand.
Difference in code perspective:
-
In ERC721, we have balances mapping like:
mapping (tokenId => address) balances;
, so that means onetokenId
cannot represent more than one address. -
In ERC1155, we have mapping like: `mappint (address => tokenId => int), so this means each token id have a balance. And within the contract we will restrict increasing the quantity of the token more than 1 and thats exactly the case which we have for ERC721 (becoz we just mint one and thats it). But here the mapping can actually support any number of tokens and this is how we achieve mix between fungible and non-fungible tokens. In code we do it like:
balances[address1][tokenId=0:GOLD] = 100 // setting as 100 coz we want it to be fungible tokens and one can have multiple of this balances[address1][tokenId=3:THORS_HAMMER] = 1 // setting quantity as 1 as we want it to be non-fungible token