One Smart Contract, Many Tokens

While ERC-20 and ERC-721 tokens required a new smart contract deployed for each new “class” of token, the core concept behind ERC-1155 is that a single smart contract can govern an infinite number of tokens.

Think of this like a vending machine that holds a wide variety of soda, juices, and even snacks. A customer interacts with the machine using a single secure interface (inserting a coin, pressing a button), and the machine dispenses the goodies they have selected. In the same way, an ERC-1155 contract made for a game could contain a wide variety of items, from weapons and armor to health potions, magic scrolls, and more.

Each of these items could be “fungible,” having more than one copy available. Fungible tokens are used for divisible currencies (most ERC-20 tokens), and they’re also very useful for stackable items that don’t need to be differentiated, like a bundle of arrows for a bow.

One-of-a-kind tokens are called non-fungible tokens (NFTs). This structure allows every token to have its own unique parameters, history, and mirrors the real world. A pet dragon in a video game could be an NFT and have a unique name of its own, a power level, and a rich history in the game.

Batch Transfers

With ERC-1155, multiple tokens can be sent in a single transaction — offering significant savings on gas costs and preventing the need to wait for each block in single transfers.

Projects using ERC-1155 can also build Atomic Swaps with the same basic design, allowing users to exchange one kind of token for another with absolute security from fraud and no intermediate party involved.

Further Optimizations

Further experimentation by some of the authors has led to even more optimizations and dramatic gas improvements!

The Sandbox developer Ronan Sandford was able to mint more than 1,500 tokens in a block while preserving true ownership with their ERC-1155 implementation.

Horizon Games developer Phillippe Castonguay was able to use a technique called Balance Packing (storing 16 lower-resolution tokens in a single ID) to achieve 80–90% gas savings compared to regular transfers.

Phillippe was also able to achieve a transfer speed of over 155 assets per second with their ERC-1155 tokens!

Data Economy

The main characteristic of the ERC-1155 Multi Token Standard is multiple tokens instantiated in a single smart contract. This means that “creating” a new token type can be as simple as calling a function that adds a new ID to the pool of tokens available.

In comparison, creating a new token type with the ERC-20 and 721 standards means editing code and deploying an entirely new contract to an address on the Ethereum blockchain. Deploying a contract costs an enormous amount of gas (ETH) because data storage is naturally expensive on a blockchain shared by the world. Most ERC-20 contracts are based on the exact same code, with a couple of lines edited, making the rest of the code unnecessary. That means every single one of Ethereum’s 25,000+ nodes becomes cluttered with redundant code that will remain there for eternity!

There’s also the operational overhead of needing to be notified of each new ERC-20 or ERC-721 contract address every time a new token is launched. One hundred new tokens would mean 100 new contracts to watch — for every wallet and every piece of software that must be made aware of the token even existing.

Therefore, while the previous two standards are good for narrow use cases — either a single currency or a single class of NFT — the vast majority of creators will benefit from ERC-1155’s ability to create new tokens on the fly and represent more than a single “type” without the duplication of identical contracts.

Strict Rules Make Tokens Reliable

An incredible feature of the ERC-1155 token standard is made possible by the strict set of rules a token must follow.

ERC-1155 tokens are the first type of token that can execute a deterministic smart contract function by simply sending a token to an address.

This is huge.

By simply sending a token to a DEX exchange address, the exchange could immediately return another token back to the sender’s address. Similarly, a blockchain game could perform a game function as soon as it receives an ERC-1155 token from a user. Tokens could be wrapped, converted, crafted, or escrowed with no need to access ABIs or interact with the smart contract directly.

This type of functionality was initially proposed in ERC-223, but the standard failed to catch on. ERC-721 also implemented “safeTransferFrom” but has the fatal problem of not strictly requiring this for all transfers, meaning that users can permanently lose their tokens and contract authors can’t rely on guaranteed execution when sending a token.

The decision to make this strict in ERC-1155 means that reliable networks of smart contracts and tokens can now begin to build upon this powerful functionality. All the user needs to do is send their token to an address to trigger an awesome chain of events.

Metadata

One of the major updates to the ERC-1155 standard in the last year was the decision to move all metadata about a token to an external JSON file. This was heavily inspired by the ERC-721 Metadata Extension, but we added some improvements.

No More Legacy Metadata

Symbol: (found in the ERC-20 and ERC-721 standards) was not included as this wasn’t a relevant piece of data for virtual items/assets. These 3-letter symbols are normally only used in tickers and for currency trading, but they aren’t as useful when you are tokenizing more general items.

Name: was also removed from the core standard. Why? In many use-cases, storing a name on the blockchain would be overkill. Instead, each token’s name can now be defined in the JSON Metadata Standard.

ID Substitution

By using the substitution string “{id},” an ERC-1155 contract can now point to an infinite number of token URIs without storing any additional data on-chain. This can even be used to point to a web service that hosts dynamically generated token JSON for each token in a database. The {id} string can also be used inside the JSON itself to automatically link to imagery for each token. This significantly reduces the overhead that’s required for developers to display metadata for large collections of tokens.

Localization

Since token information is defined in JSON format, localization is now possible for multiple languages using {locale}. Wallets and software that supports multiple languages can display alternate versions of token names, images, and any other data.

Guaranteed Log Trace

As the Ethereum ecosystem continues to grow, many dapps are relying on traditional databases and explorer API services to retrieve and categorize data. The ERC-1155 standard guarantees that event logs emitted by the smart contract will provide enough data to create an accurate record of all current token balances. A database or explorer may listen to events and be able to provide indexed and categorized searches of every ERC-1155 token in the contract.

Smart contracts no longer need to maintain indexes of every token ID, and IDs don’t need to be sequential in any way.

This is a radical departure from enumeration (the ability to browse through all tokens on-chain), but it brings a significant benefit in efficiency and even allows for an entire standardized record of every token mint, burn, and transfer. This has not been possible in a standardized way until today and will permit cool ecosystem benefits like deep data analytics on tokens and rich token explorers.

Imagine being able to rewind and fast-forward through time and analyze usage patterns and life cycles of completely different ERC-1155 tokens, regardless of which smart contract is being analyzed.

Token owners will be able to learn more about their assets, such as exactly when their particular token was minted, and in the future, tools may be developed which would provide useful insights for companies building on this technology.

Conclusion

The ERC-1155 standard is the culmination of a year of hard work by the blockchain community. If you are planning on implementing ERC-1155, you can view the entire standard, as well as the rationale behind each decision here.

You can also visit the original issue thread to see the discussion history:

To create an ERC-1155 token contract of your own, Enjin’s official reference implementation is open-source on GitHub:

You can use this code as a starting point for your own smart contract. You might also consider using the Enjin Platform, the most feature-rich set of blockchain development tools for developers and non-developers alike.