Understanding NFT(Non-Fungible token) ERC-721 standard.

In Ethereum there are two types of tokens, they are fungible and non-fungible tokens. The ERC-20 standard is used to create fungible assets. While the ERC-721 Standard is used to create non-fungible assets.

Fungible assets are assets you can exchange for other assets, for example, the US dollars can be exchanged with another currency.

Fungibility is defined as the ability for a good or asset to be readily interchanged for another of like kind.

Non-fungible assets are assets you cannot exchange for another asset, it is a unique asset that cannot be exchanged. An example of this kind of asset is a piece of art.

The way we identify an asset as an ERC 721 is different, for the ERC-20 we just need to know the ethereum address of the smart contract, but for the ERC 721, we need to know the address and the tokenID. The tokenID is an integer that uniquely identifies an asset inside the ERC-721 contract. This means a single ERC-721 smart contract can store several assets, while the ERC-20 smart contract can only store one asset.

erc721.PNG

Now let us see the implementation. This is the ERC-721 Interface, the standard used in creating any smart contract that contains non-fungible assets. This standard contains functions and events that you will need to implement to be able to create a non-fungible ERC-721 asset. Let's look at the standard

You can get the standard from the ethereum.org website with this link ERC-721 Standard

The balanceOfAddress function in the ERC-721 does not show the amount of tokens left in the address, but instead, it shows the number of assets that are owned by this address.

The ownerOf function, when given a toeknId shows which address has or owns the asset in the smart contract.

Unlike the ERC-20 standard that has two transfarFrom functions, one for delegated transfers and the other for transferring tokens, the ERC-721 standard just requires just one transfer function. Here the function takes in the tokenId and then transfers the assets. Also notice that we did not specify the value or the quantity of tokens we will need to transfer, this is because the asset is unique and non-fungible

The Approve function takes an address and the tokenId, to be able to approve an address for a specific asset. Also, you don't need to specify the quantity.

If you want to know which address has been approved for a specific tokenId, you can go to getApproved function, this allows you to input the tokenId as an argument to get the address, to know if this address has been approved or not.

The setApprovalForAll function allows you to approve an address for all your token. If you want to know if the address has been approved for all the tokens, you can check it with the isApprovalForAll function.

Finally, we have two other functions, the safeTransferFrom function, these function transfers token in the safest ways. What the function does is check if the recipient is a smart contract. If the recipient smart contract does not implement the interface of the ERC-721, the transaction is going to fail.

If you want the receiver smart contract to be able to receive the ERC-721 Token, you need to implement the ERC721TokenReciever function.

This is just the basic explanation of the ERC-721 standard. In the next article, we will attempt to use this standard to create a non-fungible token(NFT). You can follow me on Twitter to follow my journey into becoming a Blockchain developer.

To understand in-dept the ERC-721 standard, check the resource from the ethereum.org website (ethereum.org/en/developers/docs/standards/t..) .