Understanding ERC721x Token Standard

Non-fungible tokens (NFTs for short) really took off after CryptoKitties pioneered their use in blockchain-based gaming. They provide a way to attach data to a crypto token, beyond just the value an ERC20 token would.

This new token standard was called ERC721, and it allowed for unique collectibles to be issued and traded on the Ethereum blockchain. Unlike physical collectibles that have to be verified by a human to be authentic, these digital assets are provably authentic. Unlike ERC20 tokens that are “fungible” — i.e. equally interchangeable since all tokens are worth the same — ERC721 tokens are unique and cannot be substituted for one another.

As Loom’s PlasmaChain is a blockchain optimized for games, it stands to reason one of the popular pieces of discussion is the ERC721 token standard.

ERC721 defines a class of an item, with each token having different attributes. For example, CryptoKitties (follow along with the code here) has a Kitty class (line 241) that defines the basic format for a Kitty as having genes, birthtime, matronid, sireid, etc. When a new Kitty is minted, these variables are customized, so all Kitties have the same structure in terms of the variables they have, but have different values for each variable.

This works great for a collectibles game like CryptoKitties with only one type of collectible (i.e. Kitty), but fails when you want to have multiple types of collectibles. If you wanted to add Kitty Toys as a collectible, you would have to create a new ERC721 contract. And creating a separate contract for each type of collectible quickly becomes unscalable.

To solve this, there is an extension of the ERC721 standard: ERC1178. ERC1178 allows for multiple types of collectibles to be defined in the same ERC1178 contract. That means it allows any quantity of a given type of collectible to be transferred at once, which is useful when talking about cheap collectibles that might not be valuable individually, but valuable in bulk.

At first glance, ERC1178 seems like the perfect solution to the problem, but there’s a catch. It breaks compatibility with existing wallets and exchanges. In order to implement ERC1178, you not only have to implement it in your application, but you also have to hope that the wallets your players are using also support that specification.

Enter ERC721x

ERC721x is Loom’s extension of ERC721. It’s an ERC721-compatible token that supports multiple fungible classes.

ERC721x is an ERC721-compatible token that supports multiple fungible classes.

Using ERC1178 as the base, the ERC721x has a very thin optional layer of features to support crypto-collectibles, and has everything wrapped in an ERC721 compatibility layer, so it is supported by the current wallets and exchange infrastructure. The compatibility layer keeps the mint function that allows for minting single ERC721 tokens as needed.

You can see the full code for an ERC721x token on GitHub here.

Specifically, the ERC721x compatibility comes in the form of the mint() function which we can see in action.

The header of this function is the same as the function in a regular ERC721 contract, but the internal logic checks to see if that type of token exists, and if it does, prints another copy of it. This allows for copies of multiple different types of assets. Instead of 10 Fire Minion cards being 10 different tokenIDs, they all will have the same id and an adjustable quantity in your inventory.

This means that you can take ERC721 assets on Ethereum and trade hundreds of copies of a given asset for the cost of just one ERC721 transfer! For developers, you can include multiple types of assets in the same ERC721 contract, helping to create a more cohesive user experience.

Read more about the ERC721x token here.

To deploy ERC721x for your own token contracts, you can clone this repository. In there, you’ll find the code for the interface and receiver, and even a reference implementation to help you get started.

Loom Network is a platform for building highly scalable DPoS sidechains to Ethereum, with a focus on large-scale games and social apps.

Want more info? Start here.

Fan of blockchain gaming? Check out Zombie Battleground, the world’s first desktop and mobile card game that runs fully on its own blockchain.

And if you enjoyed this article and want to stay in the loop, go ahead and sign up for our private mailing list.