How to Create and Deploy an ERC-721 (NFT)

How to Create and Deploy an ERC-721 (NFT)

There has been a high demand for non-fungible tokens (NFTs), as artists and creatives of all kinds have started monetizing their work through their utilization. 

If you have ever wanted to create a collectible NFT and showcase your work, verifiably, on top of the Ethereum blockchain network, in that case, the ERC-721 token standard is the right choice for you to make.

How to Create and Deploy an ERC-721 (NFT)

Ethereum created this token standard as a means of allowing software developers access to the convenient deployment of their NFTs and ensuring that they are compatible across the broader ecosystem.

Today, we are going to go over just about everything you need to know when it comes to the creation as well as the deployment of ERC-721 tokens.

GET ACCESS TO ETHEREUM

Key Points:

  • Non-Fungible Tokens (NFTs) are crypto assets that are indivisible, unique, and distinct. They do not have any interchangeability, and they are made up of identifying information that is stored in their smart contract.
  • ERC-721 is a token standard that defines numerous functions that make it compliant with ERC-20, which is another Ethereum token standard and has the main goal of simplifying the process of existing wallets displaying the information of the token and its features.
  • Some of the key functions of the token standard are the fact that it features ownership responsibilities, as well as functionality surrounding the storage and showcase of metadata for each NFT. 
  • NOWNodes is a blockchain-as-a-service provider that will allow you to access and monitor the Ethereum blockchain through the utilization of a node or a block explorer with a simple API key connection.

What is ERC-721?

ERC-721 is essentially a token standard built to allow NFTs to be compatible across a wide range of functionalities within the Ethereum (ETH) ecosystem and blockchain as a whole. In other words, this defines how non-fungible tokens are created on the Ethereum Virtual Machine (EVM) so that the tokens can be compatible with any other EMV-compliant blockchain as well. 

To get a better perspective of how ERC-721 works and why it plays an important role across the Ethereum ecosystem, we need to look at some of the specific functions or features that the tokens need to have. 

The tokens need to have high compliance, a unique ID, multiple product management, admin tools, subscriptions and newsletters for immediate upgradations, embedded Web3 checkout button and support for MetaMask, easy transfers, 

Furthermore, some of the functions of ERC_721 tokens include the name, symbol, total supply, and balance. There are also ownership responsibilities, such as the owner, approve, take ownership, and transfer. 

What is ERC-721?

The metadata within these NFTs is an optional feature that provides an interface for discovering it or linking the data associated with a specific token.

In any case, there is a lot that goes into following this token standard, as there also needs to be transfers and approvals. 

GET ACCESS TO ETHEREUM

Pros and Cons of NFT

Pros

  • Marketplace Efficiency
  • Fractionalized Ownership of Physical Assets
  • Safe Blockchain Technology
  • Access to ownership of something unique and exclusive
  • Potential to grow in value 

Cons

  • Uncertain value
  • NFTs are not liquid
  • NFts can be volatile cryptocurrencies
  • There is potential for fraud or scammers within the NFT space

How to Create ERC-721

Creating and even deploying a smart contract with Solidity might sound like a daunting task. However, there are only a few things that you need to do in order to fully get your code up and running on the blockchain.

We will be utilizing tools such as the OpenZeppeling Wizard that will offer you access to click-and-write functionalities as a means of creating composable and secure smart contracts quickly.

The technology that we will be using to accomplish this goal is Alchemy, OpenZeppelin, Remix, and an Ethereum testnet.

  • Step 1: Go to OpenZeppelin

Navigate to OpenZeppelin, after which, on the Wizard tab, you can click on the ERC-721 option. Note that all of the NFTs are ERC-721 tokens.

Here, we want the tokens to be mintable and have Enumerable and URI storage as features.

You can also name your token here and enter the desired symbol. 

Now, click on “Open in Remix”.

The code will look something like this by the end of your selections:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import “@openzeppelin/[email protected]/token/ERC721/ERC721.sol”;
import “@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Enumerable.sol”
import “@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol”;
import “@openzeppelin/[email protected]/utils/Counters.sol”;

contract NAMZZ is ERC721, ERC721Enumerable, ERC721URIStorage{
   using Counters for Counters.Counter;

   Counters.Counter private _tokenIdCounter;
   uint256 MAX_SUPPLY = 5000;

   constructor() ERC721(“MyToken”, “MTK”) {}

   function safeMint(address to, string memory uri) public{
       uint256 tokenId = _tokenIdCounter.current();
       require(tokenId <= MAX_SUPPLY, “Sorry, all NFTs have been minted!”);
       _tokenIdCounter.increment();
_safeMint(to, tokenId);
       _setTokenURI(tokenId, uri);
   }
   
// The following functions are overrides required by Solidity.

   function _beforeTokenTransfer(address from, address to, uint256 tokenId)
       internal
       override(ERC721, ERC721Enumerable)
   { 
      super._beforeTokenTransfer(from, to, tokenId);
   }
   
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
       super._burn(tokenId);
   }

   function tokenURI(uint256 tokenId)
       public
       view
       override(ERC721, ERC721URIStorage)
       returns (string memory)
   {
       return super.tokenURI(tokenId);
   }

   function supportsInterface(bytes4 interfaceId)
       public
       view
       override(ERC721, ERC721Enumerable)
       returns (bool)
   {
       return super.supportsInterface(interfaceId);
   }
}

Ensure that you update the code as in the above example.

There are a few changes made within it, such as the removal of the ownable part of the Solidity program, as the goal here is for people to mint the NFTs. the MAX_SUPPLY was updated to 5000 as well, so it limits the NFTs.

  • Step 2: Using Alchemy to Create an App

In this next step, we need to create an Alchemy account. Then, we can click on “Create App.”

We can name it anything we want to. 

Then, click on “View Key” and copy the HTTPS address.

  • Step 3: Adding a Network to MetaMask

Create your network on MetaMask by clicking on “Add Network.” 

You can name the testnet anything you want to and paste the HTTPS URL that was copied with alchemy. Then, you will need to add an ID for the testnet and enter ETH as the symbol. Click on “Add Network”.

In this guide, we will be using the Goerli Test Network, so you can add that. Furthermore, you can test Ethereum from the Goerli faucet, found at this link. Note that you will need to link it with your Alchemy account and enter your address, after which you will get the test Ether (ETH) within a span of seconds.

GET ACCESS TO ETHEREUM

 

How to Deploy ERC-721

With all of the aforementioned steps completed, we can now move on toward compiling and deploying the ERC-721 smart contract on the Goerli Testnet.

  • Step 1: Utilizing Remix

You will need to navigate back to the Remix website, after which you can click on “Deploy” and select “Injected Web3 ” as the Environment. Here, it will get connected automatically, after which you will get the address of your MetaMask, alongside the balance sheet. Select the smart contract in the “Contract” tab, and click on “Deploy.”

  • Step 2: Formatting the NFT Metadata

If you want NFT marketplaces such as OpenSea to pull in the off-chain metadata for the ERC-721 tokens, in that case, the contract will be required to return a URI pointing to the hosted metadata.

To find this URI, OpenSea, Rarible, as well as any other popular marketplace that supports the token standard will use the tokenURI method that is contained within the ERC721Uristorage standard.

What you need to do here is navigate to the OpenSea developer documentation, where you can copy the metadata structure. Afterward, you can paste it into the JSON online editor and edit the description.

{
  “description”: “This NFT proves that I have deployed an NFT on Ethereum Goerli”,
   “external_url”: “https://alchemy.com”,
   “image”: “”,
   “name”: “MyToken”,
  “attributes”: [
    {
      “trait_type”: “Colour”,
       “value”: “Mixed”
    },
     {
      “trait_type”: “Coolness”,
       “value”: “A lot!”
    },
     {
      “trait_type”: “Token Standard”,
       “value”: “ERC721”
    }
  ]
}
  • Step 3: Creating and Uploading the Metadata on IPFS

IPFS stands for the Inter Planetary File System. If you want to upload the metadata here, you will need to create a FileBase account and verify your email. After you log in, you can click on the “Create Bucket” button, and you can name it starting with small case letters. For example, “mytoken-nft”. Select IPFS and click on “Create.” You can then upload the image that you want to make as an NFT, click on the image, and copy the IPFS Gateway URL.

You can then enter the link in the image section of the JSON file, and save it in the name of “metadata.json,” after which you can upload it on Bucket in FileBase. 

  • Step 4: Minting the NFT on the Goerli Testnet

You can then navigate towards Remix and click on “safeMint”, after which you can paste your address and this string into the uri field:

ipfs://<your_metadata_cid>

Click on transact, and a MetaMask pop-up will appear, prompting you to pay the gas fees. Here, simply click on “Sign,” and you can mint your NFT.

You then need to do the same with the tokenUri method, where you can insert “0” as the id argument. 

Conclusion

That is everything you need to know when it comes to creating and deploying an ERC-721 token (NFT) on top of an Ethereum testnet. In this example, we utilized Goerli.

If you want to keep track of everything that occurs on-chain, you can utilize the NOWNodes blockchain-as-a-service provider to keep track of all of the transactions that occur, or just get any other blockchain data that you require.

GET ACCESS TO ETHEREUM