Search⌘ K
AI Features

ERC721 and ERC721Enumerable

Learn how to create and manage non-fungible tokens (NFTs) in Solidity by implementing the ERC721 standard and its ERC721Enumerable extension. Understand token ownership, minting, metadata storage, and how to retrieve NFT IDs owned by an address both off-chain and on-chain to enhance your blockchain game development skills.

Tokens and fungibility

A token is an on-chain representation of something valuable (experience points in a game, currency, voting rights, digital assets, identity, credentials, and so on).

There are two types of tokens: fungible and non-fungible tokens (NFT).

Fungible assets are indistinct and interchangeable. Like US dollars, only their amount matters. It doesn’t matter which particular $1 banknote we own; they all have the same value. What matter is how much we own. Non-fungible assets are distinct and unique, like Rembrandts; which particular artwork we own does matter—some are more valuable than others.

That said, both are valuable assets, so we care about securely proving their authenticity and ownership. For tokens, this is managed by a token contract, which maps tokens with the address of their owners and provides other utilities.

In blockchain games, tokens can be used to manage different aspects of the player experience.

  • Access: Ownership of a certain NFT or payment of a certain number of fungible tokens can act as a toll to access the game.

  • Identity: An NFT can represent the player's identity and their in-game character.

  • Rewards: Experience points can be associated with a particular NFT identity and later translate into payments in fungible tokens. In-game items can also be represented with NFTs and owned by players.

In this lesson, we'll build a simple NFT contract to use in our games.

The ERC721 standard

NFTs are defined by contracts that follow the ERC721 standard. An implementation of such a standard can be found in the OpenZeppelin contract ...