Creating Your own ERC-721 Token

Written by dameeolawuyi | Published 2022/05/10
Tech Story Tags: blockchain | tatum_io | blockchain-writing-contest | erc20 | ethereum | erc-721-tokens | non-fungible-token | openzeppelin

TLDRvia the TL;DR App

Do you want to know how popular NFTs are built especially on the Ethereum blockchain? Then grab this piece and some juice. If you are a smart contract developer, chances are, you might have come across this concept and if you haven’t, this is one of the concepts you should be familiar with.

What to expect from this article?

  • This article would walk you through the meaning of the Erc-721 token.
  • What makes the Erc-721 token different from the Erc-20 token?
  • Component of an Erc-721 token.
  • How you can create your own unique Erc-721.

Feel free to jump to whatever theme is more of a concern to you. Let’s dig.

What is the ERC-721 token?

ERC- 721 token is the standard for creating Non-fungible(unique) tokens. It’s some sort of agreed method of creating tokens that are unique or distinct on the Ethereum blockchain. Non-fungible tokens are interchangeable units of value like digital arts, writings, and pictures. Almost anything can be made into an NFT even real-life goods. I do understand we might have curious minds who aren’t into blockchain development here. So, let’s simplify things.

The ERC-721 token is an Ethereum blockchain standard for writing non-fungible(distinct) token smart contracts. If you intend to write codes on the Ethereum blockchain, the ERC-721 is the standard code of functions that your contract must implement.

How is the ERC-721 different from the ERC-20 token?

Erc-721 is the opposite of the Erc-20 token. While the Erc-20 token serves as the standard code for implementing fungible tokens(coin), the Erc-721 token is a standard for non-fungible tokens(NFTs) like digital arts, access key, lottery, and tweets and so on.

Content of Erc-721 token

The following are the functions/ method keywords that must be contained in your Erc 721 code and their meaning.

  • balanceOf (address owner): This function basically checks the amount of NFTs of the owner in question.

function balanceOf(address _owner) external view returns (uint256);


ownerOf(unit 256 tokenId): This function tells you the address of who owns this particular token by verifying the tokenId because all NFTs are unique.

function ownerOf(uint256 _tokenId) external view returns (address);
  • **setransferFrom(address from address to unit(256) tokenId, bytes *data): ***This function keyword is useful for transferring ownership of the token. If the receiver address is also a contract, the onERC721Recieved function will be invoked to ensure that this contact can accept tokens.

  • **(address from, address to unit tokenId):**Same as the previous function except that when invoked, data is set to an empty string. Solidity supports using two methods( function) with the same name but different parameters like we have here.

  • transferFrom: This function transfers ownership of tokens across addresses. One disadvantage of using this function is that it doesn't check if the receiver is capable of receiving the said tokens and if it is invoked on an invalid address, the tokens would be lost for good. To avoid this, it is best to use the safeTransferFrom function.

function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;

  • approve(address approved, unit tokenId): This enables someone asides from the owner to transfer tokens. It differs from the approve in Erc-20 in the sense that, the tokenId is specified in the parameter and not the amount.
function approve(address _approved, uint256 _tokenId) external payable;

  • setApprovalForAll(address, operator, bool approves): This function approves the transfer of all tokens from the person calling this function to the address of new operator using boolean value(true/false ).

function setApprovalForAll(address _operator, bool _approved) external;

  • get Approved(uint256 tokenId): This tells you the approved address of the tokenId.

function getApproved(uint256 _tokenId) external view returns (address);

You can choose to include a meta tag that would contain information such as token name, description and image.

"name": {
            "type": "string",
            "description": "Identifies the asset to which this NFT represents"
        },
        "description": {
            "type": "string",
            "description": "Describes this NFT "
        },
        "image": {
            "type": "string",
            "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents."
        }

How to create your own Erc-721 token.

You can simply import an interface from Openzepellin to create yours.

OpenZeppelin library has created sample contracts that can be used as the basis for your own Erc-721 and Erc-20 tokens, you should check that out and use it to create yours.

Feel free to add other functionalities that you want your ERC-721 token to have.

To create a non-fungible token on the Ethereum blockchain, the Erc-721 token is the community standard for any NFT hosted to be hosted there. It is an acronym for Ethereum Request for Comment. Possibly, there would be an update on the functionalities of this present standard but until then, we are stuck with ERC-721.

I wrote something on the ERC-20 token. You might want to catch up on that here.

Also Published here



Written by dameeolawuyi | I'm a budding smart contract developer. I enjoy documenting my web 3 discoveries through simplified writing.
Published by HackerNoon on 2022/05/10