1

I'm using a direct implementation of these in a different language and considering the deficiencies of 1155. There is no shortage of articles comparing 721 vs 1155, but all of them go on to say 1155 has better efficiency and in particular with batch transfers / mints. The only complaints I see is that 1155 is less adopted across marketplaces (irrelevant to me), and one NFT artist saying ownership is more difficult to track with 1155s - without elaborating. Does ERC-1155 contract use less gas to mint tokens?

My particular use is an infinitely mintable and tradable domain-name style contract. There is no consideration necessitating batch transfers / mints at the moment, but that alone is permissible since it could otherwise be botted. When is 721 preferrable than 1155, other than market implementation?

1 Answer 1

0

The gas savings with 1155 come from not keeping track of an additional variable which in 721 is accessible through 'balanceOf'.

If you were trying to adapt 1155 to make it non-fungible, like 721 (if you only ever mint one of a certain id), you only have one mapping [uint256 (id) => address (user) => uint256 (balance)], where balance is either 1 or 0.

With 721, you keep track of the ownerships through a mapping [uint256 (id) => address (owner)]. There is a second mapping [address (user) => uint256 (balance)] that in this case, keeps track of how many NFTs the user owns. This lets you conveniently query whether a user owns an NFT of a certain collection (Collabland discord bot queries this value through 'balanceOf' to give a member role to users). So mostly it's being used for verification processes (I know of projects that make use of this on-chain). It is however not strictly necessary, since you could always either provide an id that you know you own (which could then also easily verified on-chain), and you can provide an O(N) implementation (not callable on-chain, because it would cost too much gas) which simply loops through all ids and counts how many you own. There have been multiple ERC721 implementations floating around that do exactly this (saving gas by not tracking this second mapping).

This balance variable does not exist in 1155. The equivalent here would be to have a variable that would keep track of unique balances.

In summary, 1155 does not use a second mapping to keep track of unique balances like 721 does. This means every transfer has less reads/writes. In 1155 it's only two (ownership/balances [from], [to]), versus 3 in 721 (ownership, balance[from], balance[to]). Light versions of ERC721 can cut down to 1 variable (only ownership) and have an O(N) balanceOf implementation.

2
  • Very interesting. But I suppose despite the 1/0 turnout, balance in the 1155 map cannot be eliminated? So a light721 might be cheaper and more sensible over 1155s?
    – 14w3u7
    Commented May 15, 2022 at 17:08
  • It can be optimized to become a mapping from tokenId => owner as seen here github.com/Rari-Capital/solmate/blob/v7/src/tokens/ERC1155B.sol . ERC1155B (and the whole v7 repo will be receiving a formal audit very soon as I heard).
    – phaze
    Commented May 15, 2022 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.