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

12 min read

Overview

Digital collectibles compatible with the ERC-721 standard have become very popular since the launch of Cryptokitties and have moved forward towards mass adoption in recent months. This guide will cover how to create and deploy an NFT (ERC-721) using the OpenZeppelin standard.

Prefer a video walkthrough? Follow along with Radek and learn how to create and deploy an ERC-721 (NFT) in 20 minutes.

Subscribe to our YouTube channel for more videos!

Subscribe

What You Will Do


  • Learn about Non-Fungible Tokens (NFTs) and their use-cases
  • Create metadata for the ERC-721 token you will build
  • Upload your files to a decentralized storage system (IPFS)
  • Create and deploy an ERC-721 token using Remix.IDE

What You Will Need


  • A QuickNode endpoint (you can create one for free here)
  • A web3 wallet (e.g., MetaMask, Coinbase Wallet, Phantom, or a WalletConnect-compatible wallet) with test ETH (you can get some at the Multi-Chain QuickNode Faucet)
  • IPFS CLI installed
  • A modern web browser (e.g., Chrome)

What is a Non-Fungible Token?

Fungible means to be the same or interchangeable. For example, Ethereum tokens, all the members of a particular token class, have the same value. The same can be said of Cardano tokens. Fungible tokens are interchangeable 1:1.

With this in mind, NFTs are unique; each one is different. Every single token has unique characteristics and values. The types of things that can be NFTs are collectible cards, artworks, airplane tickets, etc. They are all clearly distinguishable from one another and are not interchangeable. Think of Non-Fungible Tokens (NFTs) as rare collectibles; each has unique characteristics, unusual attributes, and most times, its metadata.

What is ERC-721?

ERC stands for Ethereum Request for Comment, and 721 is the proposal identifier number. ERCs are application-level standards in the Ethereum ecosystem, they can be a smart contract standard for tokens such as ERC-20, the author of an ERC is responsible for building consensus with the Ethereum community, and once the proposal is reviewed and approved by the community, it becomes a standard. You can track the recent ERC proposal here. ERC-721 was created to propose the functionality to track and transfer NFTs within smart contracts.

ERC-721 is an open standard that describes how to build Non-Fungible tokens on EVM (Ethereum Virtual Machine) compatible blockchains; it is a standard interface for Non-Fungible tokens; it has a set of rules which make it easy to work with NFTs. NFTs are not only of ERC-721 type; they can also be ERC-1155 tokens.

The following are the set of functions and events defined in the ERC-721 standard:

ERC-721 Functions

balanceOf: This function is used to return the number of NFTs (Non-Fungible Tokens) owned by a specific address.

ownerOf: This function returns the address of the owner of a specific token. Each ERC721 token is unique, represented by an ID. This function allows users or applications to determine the owner of the token based on its unique ID.

safeTransferFrom (without data): This function safely transfers the ownership of a specific token from one address to another. This function checks if the recipient is a smart contract. If it is, it must implement a specific function (onERC721Received) to accept the transfer.

transferFrom: This function is used to transfer the ownership of a token from one address to another. It is generally used when the sender has been approved to transfer the token.

approve: This function is used to give approval to an address to transfer a specific token. This allows for delegated transfers, where an owner can allow another party to transfer a token on their behalf.

getApproved: This function is used to get the approved address for a specific token. If there is no approved address for the token, this function will return a null address.

setApprovalForAll: This function allows an owner of one or more tokens to approve or revoke approval for an operator to manage all of their tokens.

isApprovedForAll: This function is used to check if an operator is approved to manage all of an owner's tokens.

safeTransferFrom (with data): This function is similar to safeTransferFrom (without data) but with an additional data parameter. This extra data can be used to pass additional information during the transfer if the recipient is a smart contract. This function also checks if the recipient is a smart contract and whether it implements the onERC721Received function.

ERC-721 events

Transfer: This event is emitted when the ownership of a token changes from one address to another. The event includes details about the sender (from), the recipient (to), and the specific token (by ID) that was transferred. This event allows external listeners, like UIs or other contracts, to react to the transfer.

Approval: This event is triggered when an address is approved to transfer a specific token. It includes the current owner of the token (owner), the approved address that can now transfer the token (approved), and the specific token (by ID) that has been approved for transfer. This event enables applications to track approvals of tokens and react accordingly.

ApprovalForAll: This event is emitted when an owner either approves or revokes the approval for an operator to manage all of their tokens. It includes the owner's address (owner), the operator's address (operator), and a boolean indicating whether the operator was approved or not (approved). This event enables applications to track which addresses have been given rights to manage all tokens of a certain owner.

Use Cases of Non-Fungible Tokens (NFTs)

Get Test ETH

Now that we know what ERC-721 tokens are and how they work, let’s see how we can build and deploy our own tokens.

We’ll deploy our contract on the Ethereum Sepolia testnet. To get started, you will need the MetaMask browser extension (or another compatible web3 wallet; Phantom, WalletConnect-compatible) and some test ETH, which you can get by going to the QuickNode Multi-Chain Faucet. Just connect your wallet or paste in the address and click Continue. You will be prompted to share a tweet for a bonus (we recommend it!); otherwise, just click No thanks, just send me 0.05 ETH. Note that there is a mainnet balance requirement of 0.001 ETH on Ethereum Mainnet to use the EVM faucets.

Adding Files to IPFS

Before writing our NFT contract, we need to host our art for NFT and create a metadata file; for this, we’ll use IPFS - a peer-to-peer file storing and sharing distributed system. There are multiple methods for engaging with the IPFS protocol. You can either set up and operate IPFS on your own system, or opt for QuickNode as an easier solution. QuickNode simplifies your access to IPFS by managing the underlying infrastructure. This approach allows you to concentrate on your content, relieving you from the responsibilities of sustaining a local IPFS node for data pinning. With QuickNode, the technical complexities are handled for you.

We cover both ways ways to upload your files to IPFS: using the standard IPFS CLI or the streamlined QuickNode IPFS service.

Standard Method: Using IPFS CLI

Download and install IPFS CLI based on your Operating system by following the installation guide in IPFS docs.

Following are the steps for hosting the image and metadata file.

Step 1: Creating IPFS repo

Start the IPFS repo by typing the following in a terminal/cmd window.

ipfs init

Step 2: Starting the IPFS daemon

Start the IPFS daemon, open a separate terminal/cmd window, and type the following.

ipfs daemon

Step 3: Adding an image to IPFS

Go to the first terminal window and add the image to IPFS (art.png here).

ipfs add art.png

Copy the hash starting with Qm and add the “https://ipfs.io/ipfs/” prefix to it; it must look something like this https://ipfs.io/ipfs/QmQEVVLJUR1WLN15S49rzDJsSP7za9DxeqpUzWuG4aondg

Step 4: Adding JSON file to IPFS

Create a JSON file, called nft.json, and save it in the same directory as the image.

JSON file format:

{
"name": "NFT Art",
"description": "This image shows the true nature of NFT.",
"image": "https://ipfs.io/ipfs/QmZzBdKF7sQX1Q49CQGmreuZHxt9sVB3hTc3TTXYcVZ7jC"
}

Now, add the JSON file.

Take the hash beginning with Qm and prefix it with “https://ipfs.io/ipfs/”; it must look something like this https://ipfs.io/ipfs/QmUFbUjAifv9GwJo7ufTB5sccnrNqELhDMafoEmZdPPng7

Save this URL. We'll need this to mint our NFT.

QuickNode IPFS Solution: An Easier Alternative

info

To learn more about the price information of QuickNode IPFS, view our pricing plans here.

If you're looking for a more straightforward approach, QuickNode's IPFS service offers an easy-to-use, efficient solution for uploading your NFT assets. With QuickNode, the complexity of managing infrastructure is taken care of, allowing you to concentrate on your content rather than maintaining a local IPFS node.

To begin using QuickNode for IPFS, follow these steps:

Step 1: Logging in to QuickNode

Log in to QuickNode and select the IPFS option from the sidebar on the left:

Step 2: Adding an image to IPFS with QuickNode

Upload your image file quickly by dragging and dropping it or clicking to select files from your Finder/File Explorer window. In this guide, we use the image below.

After uploading, click the file name in the Files tab and click the copy IPFS URL button. Similar to the screenshot below.

https://qn-shared.quicknode-ipfs.com/ipfs/QmQEVVLJUR1WLN15S49rzDJsSP7za9DxeqpUzWuG4aondg

Step 3: Adding JSON file to IPFS with QuickNode

Create a JSON file called nft.json, replace your IPFS URL in the image field, and save it. After saving, upload your JSON file to IPFS, similar to the previous step.

{
"name": "NFT Art",
"description": "This image shows the true nature of NFT.",
"image": "https://qn-shared.quicknode-ipfs.com/ipfs/QmQEVVLJUR1WLN15S49rzDJsSP7za9DxeqpUzWuG4aondg"
}

After uploading, click the file name in the Files tab and copy the IPFS URL. It must look something like the one below.

https://qn-shared.quicknode-ipfs.com/ipfs/QmeVHZzKGEDbEbG5MVz4hUucNf4qZTRfW18AgdJNTrv22m

Save this URL. We'll need this to mint our NFT.

Creating Our Own Token

For ease and security, we’ll use the OpenZeppelin ERC-721 contract to create our NFT. With OpenZeppelin, we don’t need to write the whole ERC-721 interface. Instead, we can import the library contract and use its functions.

Head over to the Ethereum Remix IDE and make a new Solidity file, for example - MyToken.sol

Paste the following code into your new Solidity script:

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

import "@openzeppelin/[email protected]/token/ERC721/ERC721.sol";
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";

contract MyToken is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
constructor(address initialOwner)
ERC721("MyToken", "MTK")
Ownable(initialOwner)
{}

function safeMint(address to, uint256 tokenId, string memory uri)
public
onlyOwner
{
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}

// The following functions are overrides required by Solidity.

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

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

Explanation of the code above:

Line 1: Specifying SPDX license type as MIT. This indicates that the code is licensed under the MIT License, which is a permissive open-source license allowing the code to be used, modified, and distributed with very few restrictions.

Line 2: Declaring the Solidity version as ^0.8.20. This indicates that the code is written using Solidity version 0.8.20 or a compatible version.

Line 4-7: Importing necessary contracts from the OpenZeppelin library.

  • ERC721.sol: This contract is imported from the OpenZeppelin library and represents the basic implementation of the ERC721 standard. ERC721 is the standard for non-fungible tokens (NFTs).

  • ERC721URIStorage.sol: This contract extends ERC721 and adds functionality for storing and managing metadata URIs associated with NFTs. Metadata URIs typically point to additional information about the NFT.

  • ERC721Burnable.sol: This contract also extends ERC721 and adds the ability to burn (destroy) NFTs. It provides a function for permanently removing NFTs from circulation, and only the owner can invoke it.

  • Ownable.sol: This contract is used for access control. It allows you to specify an owner who has special privileges within the contract. The owner can perform certain actions that other users cannot.

Line 9: Starting the contract named MyToken and mentioning that it extends the ERC721, ERC721URIStorage, and Ownable contracts. This means that the MyToken contract inherits the functionality and properties defined in these contracts.

Line 10: The constructor function begins here. Constructors are special functions in Solidity that are executed only once during contract deployment. This constructor takes one argument, initialOwner, which is an Ethereum address.

Line 11: This line calls the constructor of the ERC721 contract with the arguments "MyToken" and "MTK". It initializes the NFT contract with a name of "MyToken" and a symbol of "MTK."

Line 12: This line calls the constructor of the Ownable contract, setting the initial owner of the MyToken contract to the address provided as initialOwner.

Line 15: Declaring the function safeMint with three arguments: to (the address of the receiver of the NFT token), tokenId (the unique identifier for the token), and uri (the URI of the JSON file associated with the token). This function can only be called by the contract owner (specified by the onlyOwner modifier).

Line 19: Minting a new token by calling the _safeMint function inherited from the ERC721 contract. It creates a new token and assigns it to the specified receiver's address.

Line 20: Setting the token URI (metadata URI) associated with the token using the _setTokenURI function inherited from the ERC721URIStorage contract. The URI is set based on the provided tokenId and uri.

Line 25-32: Implementing overrides required by Solidity for the ERC721 and ERC721URIStorage contracts. tokenURI is a function that retrieves the metadata URI associated with a given tokenId. It's marked as public and view, indicating that it's a read-only function and can be called by anyone.

Line 34-41: Implementing the supportsInterface function, which is required by the ERC721 and ERC721URIStorage contracts. This function checks whether a given interfaceId is supported by the contract and returns a boolean value accordingly.

By combining these functionalities and contracts, the code creates a custom ERC721 token contract named MyToken. This contract allows the contract owner to safely mint new tokens, associate metadata URIs with them, and supports the necessary interfaces defined by the ERC721 standard.

Now, take a minute to customize the smart contract with your own details if you'd like. You can update the token name and symbol by updating the following line - ERC721("MyToken", "MTK").

When you're finished, compile the smart contract and deploy it using Injected Provider (make sure to select Sepolia testnet on Metamask before compiling the contract). Then, paste your wallet address into the box just near the Deploy button to define the initialOwner parameter of the constructor function. Lastly, click Deploy on Remix.IDE.

If you receive an error message before deployment - “This contract may be abstract”, make sure to select the appropriate contract under the Contract tab.

Confirm the transaction in Metamask:

Now go to the “Deployed Contracts” section in Remix and expand the deployed contract. You’ll see a bunch of functions/methods. Expand the safeMint function and add the following details:


  1. Add your wallet address in the _to the field.
  2. Enter any Big number value in the _tokenId field. We suggest using '1' as it represents the first token being minted.
  3. For the _uri field, input the URI of the JSON file that corresponds to the method you used in the previous steps:
    • If you used the standard IPFS CLI method: Use the URI you obtained after uploading your file to IPFS in the Standard Method: Using IPFS CLI section. This will be the IPFS link prefixed with https://ipfs.io/ipfs/, followed by the hash of your file.
    • If you chose QuickNode's IPFS service: Use the URI provided by QuickNode after you uploaded your file in the QuickNode IPFS Solution: An Easier Alternative section. QuickNode generates a unique URI for your file, which you should insert here.

Click on transact and confirm the transaction from MetaMask. It could take a couple of minutes but you can always confirm the transaction was executed via a block explorer like Etherscan. Now you have the NFT on the Sepolia chain.

You can check other details like name, symbol, ownerOf, or tokenURI by entering the token id we mentioned earlier.

Conclusion

Congratulations on creating your very own NFT! Help your artist friends put their artistic work on the Ethereum blockchain, or become an artist yourself. Check out OpenZeppelin's Wizard for more examples.

Subscribe to our newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you’ll ever meet :)

We ❤️ Feedback!

Let us know if you have any feedback or requests for new topics. We'd love to hear from you.

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

FAQs

How to create and deploy an ERC-721 NFT? ›

4 Steps to Create an ERC721 Token on Kaleido
  1. Step 1: Create a Kaleido Account. If you haven't already, sign up for a Kaleido account here. ...
  2. Step 2: Create a Blockchain Network. To get started, create a blockchain network. ...
  3. Step 3: Create a Token Pool. ...
  4. Step 4: Create Your Token. ...
  5. Step 5: Transfer Your NFT to Metamask.
Feb 13, 2024

How are ERC-721 NFTs produced? ›

Creating an ERC-721 NFT typically requires writing, testing, and deploying a smart contract using the Solidity programming language.

How to create ERC1155 NFT? ›

If you don't already have an ERC1155 NFT collection smart contract, head to the Explore page and select the Edition Drop smart contract:
  1. thirdweb Explore Page. ...
  2. Deploy Edition Drop Contract. ...
  3. Populate metadata for the edition drop contract. ...
  4. Select the chain you want to deploy on and click on deploy. ...
  5. Deploy the Token Contract.
Jan 24, 2023

How much does it cost to deploy ERC-721? ›

I recently deployed a simple ERC721 NFT (generated using OpenZeppelin Contracts Wizard: https://blog.openzeppelin.com/wizard) and with a gas price of 150 Gwei this cost ~ 0.4 ETH, with a cost of minting each token at ~0.1 ETH.

How do I create and deploy an ERC20? ›

How to Create an ERC-20 Token
  1. Set Up your Developer Environment. First, create an Alchemy account, and set up Metamask, HardHat, and Solidity for this project. ...
  2. Write ERC-20 Token Smart Contract. ...
  3. Write a Deployment Script for your ERC-20 Token. ...
  4. Deploy your ERC-20 Token to Goerli. ...
  5. Step 4: Send Some Tokens!

What is ERC-721 example? ›

The ERC-721 token smart contract demonstrates how to create and transfer non-fungible tokens. Non-fungible tokens represent ownership over digital or physical assets. Example assets are artworks, houses, tickets, etc. Non-fungible tokens are distinguishable and we can track the ownership of each one separately.

How much does 1 NFT cost? ›

$0.0123

Which is better ERC-721 or erc1155 contract? ›

This means that ERC-1155 tokens can be used for fractional ownership or as a form of currency, while ERC-721 tokens are typically used for digital collectibles and other unique digital assets. Another difference is that ERC-721 tokens can only be traded one at a time, while ERC-1155 tokens can be traded in bulk.

Does each ERC-721 token have its own address? ›

ERC-721 Functions​

ownerOf: This function returns the address of the owner of a specific token. Each ERC721 token is unique, represented by an ID. This function allows users or applications to determine the owner of the token based on its unique ID.

How much does it cost to create an ERC token? ›

On average, the cost to create ERC20 token lies between $5000 to $10,000, depending on the type of token developed and business requirements.

How much does minting ERC1155 cost? ›

ERC1155D is completely non-fungible in the way ERC721 is, so each token has a unique identifier and a unique owner. With a mint cost of under 51,000 gas, it greatly outperforms every other existing NFT implementation in terms of gas efficiency by a very large margin with savings of 23–66%.

How to add ERC-721 NFT to MetaMask? ›

Add ERC-721 NFTs
  1. Step 1: Import tokens into your metamask wallet. Import Tokens.
  2. Step 2: Add custom token. Add Custom token. You have to specify the Token Decimal as 0. The token symbol is the same as the collection name specified in the ERC-721 contract. This token symbol can edit as well.

What are the disadvantages of ERC-721? ›

One of its key features, 'indivisibility,' has a downside. The incapacity to divide into smaller units becomes impractical in scenarios where fractional or partial ownership of certain projects is desired. Minting and transfer of each ERC-721 token needs a separate transaction, which leads to higher transaction fees.

Is ERC-721 free? ›

ERC-721 is a free, open standard that describes how to build non-fungible or unique tokens on the Ethereum blockchain. While most tokens are fungible (every token is the same as every other token), ERC-721 tokens are all unique.

How does ERC-721 work? ›

ERC-721 tokens are the standards for non-fungible tokens (NFTs). These tokens cannot be exchanged for anything of equal value since they are unique in themselves, representing a unique asset. Each NFT token is linked to different owners and has its own tokenID or metadata that makes them unique.

How do I get ERC-721? ›

Retrieve and display ERC-721 and ERC-1155 tokens
  1. Create a project directory​ Create a new directory for your project. ...
  2. Install required packages​ Install the web3 package in the project directory: ...
  3. Set up the script​ ...
  4. Set the ABI​ ...
  5. Request the metadata​ ...
  6. Display the token​ ...
  7. Run the script​
Apr 25, 2024

How to add ERC-721 NFT to metamask? ›

Add ERC-721 NFTs
  1. Step 1: Import tokens into your metamask wallet. Import Tokens.
  2. Step 2: Add custom token. Add Custom token. You have to specify the Token Decimal as 0. The token symbol is the same as the collection name specified in the ERC-721 contract. This token symbol can edit as well.

How do you create and deploy a 10000 NFT collection? ›

  1. Step 1: Create Layers in Photoshop. The first step in creating an NFT collection is to create the different layers that make up the NFT. ...
  2. Step 2: Generate NFTs and Metadata Files with Rarity. ...
  3. Step 3: Upload NFTs to the IPFS. ...
  4. Step 4: Create a Smart Contract and Mint the First NFT. ...
  5. Step 5: Sell NFTs on an NFT Marketplace.
Jan 25, 2023

How do you write and deploy an NFT Part 2 3? ›

  1. Step 1: Install Web3.
  2. Step 2: Create a mint-nft.js file.
  3. Step 3: Grab your contract ABI.
  4. Step 4: Configure the metadata for your NFT using IPFS.
  5. Step 5: Create an instance of your contract.
  6. Step 6: Update the .env file.
  7. Step 7: Create your transaction.
  8. Step 8: Sign the transaction.

Top Articles
Automatic SMS Verification with the SMS Retriever API  |  Credential Verification  |  Google for Developers
Global Trade Data: Best Datasets & Databases 2024
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6471

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.