Select Page

How to create ERC-721 token?

create erc721 token

With the rising demand for non-fungible tokens, if you desire to use and channelize a crypto collectible Dapp, ERC-721 is the right choice. ERC-721 has been the center of attraction for quite some time now, as it makes safe blockchain networks connecting to “crypto gaming” online games. Since the launch of Cryptokitties, the digital collectibles that are compatible and adhere to the ERC-721 standard have been quite popular, moving ahead in their mass utilization.

Two Ethereum Token Standards were responsible for generating major NFT tokens namely ERC-721 and other ERC-1155 blueprints. Ethereum created these standards to allow software developers for the convenient deployment of the NFTs to ensure their compatibilities with the broader ecosystem.

What are NFTs?

NFT or Non-Fungible Token can be described as an asset of crypto that is indivisible and distinct. They do not adhere to the attribute of interchangeability that can be utilized to sell in an open marketplace. The NFT is made up of identifying information that is stored in the Smart Contracts. With the help of this information, there is a fair possibility to differentiate between the NFTs, making each NFT irreplaceable.

NFTs have the attribute of uniqueness, indivisibility, and rarity. The most important attribute among these three is the uniqueness of the Non-Fungible Token based on the identity information stored in Smart Contracts, which associates with every individual unit. It assures authenticity. The feature of indivisibility states that the NFTs cannot be divided into small units. As the NFTs are scarce assets, they are rare in nature. Even though the developers can create as many NFTs as they want, their quantity is often limited to make a rise in rarity.

NFTs are supported by two specific token standards, namely “ERC-721” and “ERC-1155”. ERC-721 was the first-ever developed token standard for supporting Non-Fungible digital assets. It is also known as the Solidity Smart Contract standard that is inheritable. Therefore, developers can take assistance from the Open Zeppelin library to create the new compliant contracts. ERC-1155 is another standard for the NFTs that gives semi-fungibility to them. ERC-1155 also gives superset to the ERC-721, assisting in ERC-721 asset-building using the ERC-1155 standard.

What do you understand by ERC-721?

The full form of ERC is Ethereum Request for Comment, and 721 in “ERC-721” is the numeric proposal identifier. ERC is the application-level guideline in the Ethereum network used to define smart contract specifications for the tokens like ERC-20. It is the responsibility of the author of an ERC to establish consensus within the Ethereum community, and once the community has finalized the proposal, it becomes a standard. ERC-721 was intended to facilitate the tracking and transfer of non-fiduciary tokens within smart contracts.

ERC-721 is an open standard that defines how to create Non-Fungible Tokens on EVM (Ethereum Virtual Machine) compliant blockchains; it also serves as a standard interface for Non-Fungible Tokens and it includes a set of rules that make working with NFTs simple. Non-fungible tokens (NFTs) are not limited to the ERC-721 standard; they can also be ERC-1155 tokens.

ERC-721 defines several functions that are compliant with ERC-20. It simplifies the process of existing wallets displaying basic token information in addition to the list of the following salient features.

  • High compliance
  • Unique ID.
  • Multiple Product Management.
  • Admin tools.
  • Subscriptions and Newsletters for immediate upgradations.
  • Embedded Web3 checkout button with metamask support.
  • Easy transfers.
  • ERC721 token wallet apps for web, android, and ios
  • Roles-based permission.
  • High-end security systems.

What are the functions of ERC-721?

Functions similar to that of ERC-20

  • Name
    This field is used to specify the token’s name, which other contracts and applications can use to identify it.
  • Symbol
    Used to define the shorthand name or symbol for the token.
  • totalSupply
    This function is used to specify the total supply of tokens on the blockchain; the supply does not have to be persistent.
  • balanceOf
    Returns the number of NFTs that an address owns.

Ownership Responsibilities

  • ownerOf
    This function returns the owner of a token’s address. Because ERC-721 tokens are non-fungible and unique, they are represented on the blockchain by an ID. This ID can be used by other users, contracts, and applications to determine who owns the token.
  • Approve
    This function allows or approves another entity the authority to transfer tokens on behalf of the owner.
  • takeOwnership
    It is an optional function that functions similarly to a withdraw function in that it can be called by an external party to withdraw tokens from another user’s account. As such, takeOwnership can be used when a user has been approved to own a specified amount of tokens and wishes to withdraw those tokens from the balance of another user.
  • transfer
    It is another transfer function; it enables the token owner to transfer it to another user, similar to how other digital tokens/coins work.
  • tokenOfOwnerByIndex
    It is a recommended but optional function. Each owner may own multiple NFTs concurrently. However, each NFT is identified by a unique ID, and it can become difficult to keep track of IDs over time. As a result, the contract stores these IDs in an array, and the tokenOfOwnerByIndex function allows us to retrieve them.

The function of Metadata

  • tokenMetadata
    This optional feature provides an interface for discovering the metadata or linking to the data associated with a token.

Events

  • Transfer
    This event is triggered when the token’s ownership changes from one individual to another. It emits information about the account that transferred the token, the account that received the token, and the transferred token (by ID).
  • Approve
    This event is fired whenever a user grants another user ownership of the token, i.e., whenever the approve function is executed. It emits information about which account currently owns the token, which account has been granted permission to acquire ownership of the token in the future, and which token (by ID) has been granted permission to transfer ownership.

 

Stay ahead in the competition by leveraging the benefits of ERC tokens

LeewayHertz End-to-end Ethereum Token Development Services

What are the steps to create and deploy ERC-721 tokens?

Now that we are familiar with the concept of ERC-721 let’s move ahead and understand the steps involved in creating and deploying the ERC-721 token.

Step1: Getting test ETH

We will use the Ropsten testnet to deploy our contract. To begin with this process, you will need a browser extension named Metamask from the Ropsten faucet to create some test ETH and an ETH wallet. Next, select the option of Ropsten test network available on Metamask wallet, copy the wallet address to the next specified field, and then press the option for receiving the test Ether.

Step2: Adding Files to IPFS

The next step is to add the files to the IPFS. We will need to host our art for the NFT and make a metadata file before writing the NFT contract; we will use the Peer-to-Peer File Storing, and Sharing distributed system (IPFS). Start with downloading IPFS and then install it as per the operating system.

Follow the below-mentioned steps to host an image and a metadata file:

  • Start with the IPFS repo creation by typing the below-mentioned code in a cmd/terminal window,
$ ipfs init
  • Then begin with the IPFS daemon by separately opening the cmd/terminal window and then enter the code,
$ ipfs daemon
  • Then add an image to the IPFS by going to the first terminal window as per the code mentioned below,
$ ipfs add art.png

Then copy hash starting from Qm and attach the prefix “https://ipfs.io/ipfs/.”

  • Next, you have to add a JSON file to IPFS. Begin by creating a JSON file and saving it on the same directory in the image form.

Check out the file format of JSON mentioned below,

name: NFT Art
description: This image shows accurate nature of NFT
image: https://ipfs.io/ipfs/QmZzBdKF7sQX1Q49CQGmreuZHxt9sVB3hTc3TTXYcVZ7jC

  • The next step is to add JSON file as,
$ ipfs add nft.json

Then copy hash starting from Qm and attach the prefix “https://ipfs.io/ipfs/.” The output will look like this,

https://ipfs.io/ipfs/QmUFbUjAifv9GwJo7ufTB5sccnrNqELhDMafoEmZdPPng7

We will save this URL as it becomes useful while minting the tokens later.

Step3: Creating Token

We will be using the ERC-721 contract for a smooth NFT creation process. We will not write about the whole ERC-721 interface as we are using the Ethereum ERC-721. We also use the functions of the library contract by importing them. Move towards the Ethereum IDE and then create a solidity file. Then start importing the below-mentioned code into your newly created script of solidity.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol,
import https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol,
contract newNFT is NFTokenMetadata, Ownable {
constructor() {
nftName = Synth NFT;
nftSymbol = SYN;
}
function mint(address _to, uint256 _tokenId, string calldata _uri) external onlyOwner {
super._mint(_to, _tokenId);
super._setTokenUri(_tokenId, _uri);
}
}

The code mentioned above is understood as,

  • Line 1 specifies the type of SPDX license. These licenses will help in solving the issues of copyright.
  • Line 2 declares the version of solidity.
  • Line3, 4 and 5 of the command explain importing of Ethereum ERC-721 contracts.
  • Line 6 mentions about constructor function.
  • Line 7 command states about beginning the Contract named newNFT.
  • Line 8 gives input for the NFT symbol.
  • Line 9-12 states about initializing a symbol for the token, constructor and setting a name.

With the help of injected Web3, deploy the compiled smart contract and then approve the transaction from the metamask.

After deploying the smart contract, expand it from the “Deployed Contracts” section in Remix. It will reflect a lot of functions/methods. Then broaden the function of mint and attach the below-mentioned details:

  • Ropsten address
  • Any big number value in the _tokenid field
  • Add URI of JSON file in the _uri field obtained previously.

Click and confirm transaction from metamask. You will then have a token on the Ropsten chain. You may also verify other credentials like name, symbol, owner, or token URI by inserting the token id.

What are the benefits of ERC-721 token development?

ERC-721 tokens cover numerous business verticals like healthcare, finance, retail, e-learning, tourism, media, and entertainment, with the most prominent following benefits.

  • Piracy free

    The undeniable security and effective management make the token piracy-free.

  • Surveillance free

    The web3 platform handles overall ownership-oriented matters. Hence, tokens are free from surveillance.

  • Limited licenses

    The number of licenses imparted to the ERC721 token is very limited and scarce

  • Transferable license

    Though the tokens are non-transferrable due to their non-fungibility, their licenses are transferrable or exchangeable.

The motive behind creating ERC-721 tokens is the chance of token generation that too a unique token with solitary functions. Therefore, the uniqueness of the ERC-721 token works as a benefit. Therefore, people’s desire to get it remains inversely proportional to the number of similar tokens available. For better guidance, contact our team of developers.

Author’s Bio

 

Akash Takyar

Akash Takyar
CEO LeewayHertz
Akash Takyar is the founder and CEO at LeewayHertz. The experience of building over 100+ platforms for startups and enterprises allows Akash to rapidly architect and design solutions that are scalable and beautiful.
Akash's ability to build enterprise-grade technology solutions has attracted over 30 Fortune 500 companies, including Siemens, 3M, P&G and Hershey’s.
Akash is an early adopter of new technology, a passionate technology enthusiast, and an investor in AI and IoT startups.

Start a conversation by filling the form

Once you let us know your requirement, our technical expert will schedule a call and discuss your idea in detail post sign of an NDA.
All information will be kept confidential.

Follow Us