Introduction
In our last article, we looked at ERC-20, which gave rise to this article, in which we’ll focus on ERC-721. Unlike ERC-20 tokens, which are fungible, ERC-721 tokens are non-fungible.
“Hm, what do you mean by fungible?”
An asset is fungible if it can be interchanged with individual assets of the same type. For example, currencies
Currency like the British pound (see image above) can be used to purchase a shoe for a certain amount, say £500.
However, when someone goes to purchase the same shoe with the collectible above, which has the same value as the shoe, the seller of the shoe won’t accept it because people define the value of collectibles and currencies with different characteristics.
A football fan could purchase the same collectible for £2,000 because he/she is a fan of Mbappe and the unique properties of the collectible, whereas the shoe seller doesn’t value the collectible because it isn’t a currency.
This scenario above defines the fungibility of an asset, as certain assets cannot always be interchangeable.
Humans have a history of collecting items, from physical coins to sports cards. It’s a hobbyist’s nature to seek out rare items, especially those related to their interests. It applies to collectibles in the same way that it does to commodities. Rarity is a defining feature when purchasing a collectible.
When this is applied to the blockchain, we get digital collectibles called NFTs (non-fungible tokens). This is a one-of-a-kind digital identifier that cannot be duplicated or substituted and is stored on a blockchain.
History
ERC-721 birthed digital assets on blockchains. The Non-Fungible Standard was created by William Entriken, Dieter Shirley, and some CryptoKitties developers through an EIP (Ethereum Improvement Proposal) created on January 24, 2018.
CryptoKitties utilized ERC-721, becoming the first digital collectible on the Ethereum blockchain. Today, to create an ERC-721 token, the contract must be compliant with ERC-721 and ERC-165.
ERC-721 can be applied to physical properties, financial documents, and digital collectibles.
Functions used in ERC-721 tokens
ERC-20 like functions: name, symbol, totalSupply, balanceOf. Ownership functions: ownerOf , approve , takeOwnership , transfer , tokenOfOwnerByIndex , and Metadata function: tokenMetadata. Events: Transfer and Approval.
ERC-20-like Functions
These functions are in compliance with the ERC-20 token standard. This helps smart contracts that fit this standard perform some functions of ERC-20 tokens, such as the transfer of tokens and the querying of balances for the public.
name
This function signifies the name by which the token should be known.
symbol
This function identifies tokens with an abbreviation, thereby providing compatibility with the ERC-20 token standard.
totalSupply
This function returns the total number of tokens in a contract.
balanceOf
This function is used to find the total number of tokens in an address.
Ownership Functions
These functions define who owns a token and how ownership can be transferred.
ownerOf
Since ERC-721 tokens are non-fungible, each token is identified by a unique ID. This function helps return the address of the owner of the token.
approve
This function grants permission to another user to transfer ownership of a token on the owner’s behalf. For example, user A can call the approve function on her NFT. This will let user B access the NFT.
takeOwnership
This acts like a withdraw function for a token, enabling an external user to access a token and withdraw the token from the owner’s address. When a user is approved to own a certain token and the user calls the takeOwnership function, the token can be withdrawn from the owner’s address by an external user.
transfer
used for transferring tokens from one address to another. This function is called when the owner of a token wants to transfer that token to another address. However, the recipient address has to approve ownership of the token.
tokenOfOwnerByIndex
An NFT collector can own numerous tokens at a time because each NFT is referenced by a unique ID, so it gets difficult to select a specific token. This function keeps track of all token IDs in order to differentiate them from each other.
Metadata Function
As earlier mentioned in this article, what differentiates fungibility in assets are the unique features of an asset. References like the IPFS hash and HTTP(S) link aid in the storage of token attributes, allowing programs outside the chain to access data on the token.
tokenMetadata
This function helps identify a token’s metadata.
Events
Events are broadcasted whenever a contract calls them to listening programs both within and outside. Programs listen for events so that they can process logic using data from the broadcasted message.
Transfer
This event is broadcast whenever a token’s ownership changes, detailing the old and new owners of the token and the token’s ID.
Approval
This event is broadcast whenever a user approves another user to claim ownership of a token, detailing the current and future owners of the token and the ID of the token approved to be transferred.
Conclusion
Thanks to the ERC-721 token standard, the adoption of digital collectibles has been immense, ranging from 1/1 arts to art collections to gaming to music. The growth is exponential.
If you enjoyed this write-up and would like to reach out to me. This is my twitter handle — twitter.com/0xSalazar
Please remember to do your research. None of this is financial advice.