What is ERC-721?

In this article, we will look at the ERC-721 standard used to implement NFT on the blockchain.

As mentioned in the previous article on ERC-20. ERC is a standard used in Ethereum, however, the introduced purpose and method of use are also applicable to other blockchain mainnets. For a better understanding, we recommend that you first read the description of ERC-20 in the link below.

What is ERC-20?

Background on NFT and ERC-721

NFT stands for Non-Fungible Token. It means that it is not a fungible token, so what does a fungible token (FT) mean? First of all, tokens refer to assets that can be issued on the blockchain platform, as mentioned in the previous ERC-20 article. For example, there is USDT, a stablecoin issued on Ethereum. Each USDT token is worth about $1, and all other USDT tokens have the same value. So, as long as it is a USDT token, it can be exchanged 1:1 in a trade, because each USDT token has the same value to another. Tokens with these characteristics are called Fungible Tokens.

So, what kind of tokens have non-fungible characteristics? Let’s take CryptoKitties as an example, a famous NFT project issued on Ethereum. CryptoKitties is a blockchain-based cat breeding game, where users buy and collect cats or cross them with other species to create new cats and trade them. Tokens are used here to represent cats, each with a different shape and character. Some traits may be rare, while others may be worthy of motivating a particular user to purchase. Therefore, each has a different value depending on the characteristics of the CryptoKitties image connected to the token, but there is a limit to reflect these characteristics through the use of ERC-20 standard which issues tokens with replaceable characteristics. For this reason, a token format used when issuing tokens with non-fungible characteristics is required. Defined as NFT, a new standard ERC-721 has emerged to implement it.

NFT differs from FT in that there is something of value linked to the token. In the case of CryptoKitties described above, ownership of the cat image is applicable. The image itself is public data on the internet and anyone can use it. However, only the token owner can trade cats or claim they are theirs. Expanding this, it is also possible to trade ownership of works of art that are considered of real-world value when issued in NFTs. NFT is also called Digital Ownership because it can be viewed as a role that extends to a form that can be traded on the blockchain by issuing something of unique value as a token.

NFTs can be said to be similar to cases of how the real estate and the certified copy of the title to it are separate. However, since NFT is a token that exists on the blockchain, it is issued by a decentralized smart contract rather than a centralized entity, and has the characteristic that forgery is impossible.

ERC-721 standard

Like ERC-20, NFTs issued with ERC-721 require a common interface to enable remittance and exchange. For example, such as the Transfer function used in the ERC-20. Since NFTs are tokens of intrinsic value, an interface has been added to link the owner lookup indicating who the token's owner is, and metadata indicating the data characteristics of the NFT.

Below is the interface of ERC-721. (Pay attention to the name after the function rather than the code.)

function ownerOf(uint256 _tokenId) external view returns (address); 
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
function approve(address _approved, uint256 _tokenId) external payable;
function balanceOf(address _owner) external view returns (uint256);

The main point of trading or checking FT is focused on viewing the Amount. Quantity is important to indicate how many tokens to send, how much balance they have, and so on. However, since each NFT token has a unique value, NFT is managed through a token ID within the same project. Even in CryptoKitties, all cats were issued under a singe contract, but each image is mapped to a unique token ID.

ownerOf is an interface that tells you who the owner is via token ID (_tokenID). The token number assigned to the NFT tells you which address has ownership. It can be seen that even in the case of approve, which grants permission to transfer tokens for a transaction, or transferFrom, which transfers ownership, an operation is performed based on the token ID of the NFT rather than setting the quantity that FT uses.

In addition, the standard includes balanceOf, which queries the owner (_owner) and tells how many NFTs the address has.

NFT metadata

ERC-721 is an interface that defines functions necessary for smart contracts to implement NFT. However, unlike FTs, NFTs often contain various information independent of the ownership of tokens on the actual blockchain. For example, in the case of CryptoKitties, it is necessary to specify and indicate what characteristics each cat has, and this type of data is called metadata.

The reason that tokens and metadata are managed separately is that various information may be needed to express NFTs, and it is inefficient to store them directly on the blockchain. When publishing an image or video to NFT, it is expensive to store the file directly on the blockchain. Therefore, the common method used is to use an external storage and upload only the link where the image is stored to the blockchain. As external storage, a decentralized distributed storage platform such as IPFS can be utilized.

Metadata can be freely written depending on what kind of NFT it is, and it is not standardized because the characteristics of each field are very different. However, as shown below, functions such as the name indicating the name of the NFT, the symbol indicating the unit of the token, and tokenURI indicating the external address where the data connected to the token is stored are commonly used metadata formats.

function name() external view returns (string _name);
function symbol() external view returns (string _symbol);
function tokenURI(uint256 _tokenId) external view returns (string);

In this article, we looked at some representative interfaces to understand ERC-721. If you are interested in learning in details, please refer to the standard documentation.


Last updated