
NFTs are now sweeping the globe. By commercializing goods and services, they are transforming every facet of our society. The enormous sales these NFTs have generated through the crypto community have utterly upended the digital collectibles and art market. As the use of digital tokens has grown, many token standards have emerged. In our last article, we talked about the notorious ERC-20 token. This lesson will show you how to create an ERC-721 contract. Learn more about the ERC-721 standard and how to develop a smart contract by reading about it.
An Introduction to the Fabled ERC-721 Standard

Considered to be the legendary standard that initially gave rise to the NFT craze, ERC-721. The success of this standard is due to several ground-breaking characteristics. It makes it simple to transfer NFTs across accounts and exchange these virtual coins for other fiat money. Its ideas include fractional ownership of private property, blockchain ownership of original digital art copies that fetch millions of dollars, and distinctive avatars made available to the general public as membership in an exclusive club.
Although it is sometimes mistaken with ERC 20, the former calls for the creation of a contract to include basic information, such as a name or symbol, a unique id, and, in most circumstances, a URI or Uniform Resource Locator, the fact that ERC 721 is unique and cannot be copied makes it different from other ERCs. Holding and exchanging non-fiduciary tokens within smart contracts became simpler because of the ERC-721 standard. After reviewing some ERC-721 fundamentals, let’s create a contract using it.
Employing Open Zeppelin to Draft A Simple ERC-721 Contract

The following tutorial will use Remix as our default IDE for writing, compiling, and deploying the contract. Let’s get started now
Head over to Remix and create a new file named “HelloWorld.sol”. This is where we will write our smart contract
Before initializing the code, we have to define the Solidity compiler version for our contract by using pragma along with the underlying license:
// SPDX-License-Identifier:UNLICENSED
pragma solidity >=0.8.0;
After declaring the Solidity compiler version, we move on to import the appropriate Open Zeppelin libraries, notably ERC721, from their official source.
The ERC721 library contains the fundamental definitions required for a contract to be considered ERC-721 compliant.
import “@openzeppelin/contracts/token/ERC721/ERC721.sol”;
We will name our contract Hellonft and declare it as ERC-721 compliant, along with defining the symbol as HONFT
contract HelloWorld is ERC721(“HelloWorld”, “HONFT”) {
Next, we initialize the tokenId( unique identifier for each token) to 0
uint tokenId;
We create a mapping with the address as the key and tokenMetaData as the value.
mapping(address=>tokenMetaData[]) public ownershipRecord;
The tokenMetaData struct is designed to hold each token’s tokenId, timestamp, and tokenURI in one place so that they may be linked to the ownershipRecord of addresses in a complete fashion.
struct tokenMetaData{uint tokenId;uint timeStamp;string tokenURI;}
Now we begin writing our mintToken function. Minting enables sus to tokenize various assets. We mint the sample image in the .png format.
function mintToken(address recipient, string memory url) public {
We now use the _safeMint method to initiate the minting process imported from the ERC721 contract and push the tokenMetaData to the receiver to maintain our own ownershipRecords. We’ve hardcoded the same.png file as the URI for minting any token in our contract to simplify things.
_safeMint(recipient, tokenId); ownershipRecord[recipient].push(tokenMetaData(tokenId, block.timestamp, url)); tokenId = tokenId + 1; }}
Now you can move on towards deploying this contract on any test net, including Remix. The complete contract should look like this now:
// SPDX-License-Identifier:UNLICENSED
pragma solidity >=0.8.0;
import “@openzeppelin/contracts/token/ERC721/ERC721.sol”;
contract HelloWorld is ERC721(“HelloWorld”, “HONFT”) { uint tokenId; mapping(address=>tokenMetaData[]) public ownershipRecord;
struct tokenMetaData { uint tokenId; uint timeStamp; string tokenURI; }
function mintToken(address recipient, string memory url) public { _safeMint(recipient, tokenId); ownershipRecord[recipient].push(tokenMetaData(tokenId, block.timestamp, url)); tokenId = tokenId + 1; }}
After calling in the mintToken function, you will have successfully tokenized your very first NFT
Final Thoughts

In this lesson, we led you through creating your NFT ERC-721 contract using Open Zeppelin. This article also refreshes the fundamentals and justifications behind the most widely used token standards. We hope the information here helps you draft your first NFT smart contract. As usual, be confident and have fun coding!
Creating A Simple ERC-721 Smart Contract was originally published in CryptoStars on Medium, where people are continuing the conversation by highlighting and responding to this story.
