Are You Using AI In Your Job?

We want to understand the real-world applications of AL and ML in business and the impact it will have on all our jobs.

Want to help? Complete the survey, your insights could make a big difference. It will just take one minute.
You'll be the first to get access to the final report.-->

Creating Your Own ERC-721 NFT: A Step-by-Step Guide using NFT.Storage & Remix IDE

| February 24, 2023

Non-Fungible Tokens, or NFTs, are controlled by a standard on-chain smart contract called ERC-721. Typically, an on-chain ERC-721 contract generates token IDs by associating each token ID with a URL that points to off-chain digital assets. 

As the expectation for content permanence and the Web3 philosophy means hosting NFT metadata, images, and other assets on a long-term decentralized off-chain storage, this adds additional (but necessary) layers to factor in the capabilities of the underlying storage hardware.

This article will guide you on uploading files to NFT.Storage (a free, decentralized off-chain storage), creating your NFT’s metadata, and minting an NFT on-chain. Note that this article is written for those with a basic understanding of JSON and familiarity with Remix IDE. 

How to Upload Files to NFT.Storage

NFT.Storage is a free, decentralized storage platform powered by IPFS and Filecoin. InterPlanetary File System (IPFS) addresses all files you upload, while Filecoin provides consensus mechanisms for long-term content persistence with Proof-of-Spacetime and Proof-of-Replication.

IPFS generates an IPFS URL pointing to any file uploaded to NFT.Storage. Each IPFS URL consists of an IPFS scheme (ipfs://) followed by a unique content identifier (CID). You can use IPFS URLs in your NFTs metadata to ensure your NFT always refers to the intended asset.

To upload files to NFT.Storage, follow these steps:

  1. Go to NFT.Storage and log in.
  2. If you are not on the files page, click on Files to go to your files page.
  3. Click on the Upload button to load the file upload page.
  4. Click on the Choose File button to select a file from your device.
  5. Click on Upload to upload your files.
  6. Once your files are uploaded, click on the Action button to copy the following information:
  • IPFS URL (ipfs://<cid>)
  • IPFS hash of the uploaded files known as CID.

In practice, you will first upload an NFT’s digital asset to get its IPFS URL and then insert the resulting URL in your NFT’s metadata before uploading the metadata to NFT.Storage. From here, you’ll use your metadata’s IPFS URL for minting on-chain.

How to create NFT metadata

Metadata provides information about NFTs, usually in JSON format.

NFT marketplaces use your JSON metadata to display information for buyers. Therefore, your metadata should be compatible with the official NFT metadata standard or Enjin’s suggestions.

To create basic NFT metadata in JSON format, follow these steps:

  1. Create a file and name it as you wish by adding the .json extension.
  2. Copy and paste the following basic recommendation for NFT metadata JSON Schema:
{

    "title": "Asset Metadata",

    "type": "object",

    "properties": {

        "name": {

            "type": "string",

            "description": "Identifies the asset to which this NFT represents"

        },

        "description": {

            "type": "string",

            "description": "Describes the asset to which this NFT represents"

        },

        "image": {

            "type": "string",

            "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."

        }

    }

}




Edit it as you wish by implementing your NFT's image's IPFS URL as follows:

"image": {

           

            "description": "IPFS URL HERE"

        }
  1. Save the file with your edited metadata and upload it to NFT.Storage.
  2. Once the metadata is uploaded, click on “Action” to copy the IPFS URL (ipfs://<cid>) of the metadata. In the ERC-721 standard, this URL behaves as the token URI.

Once you have the metadata IPFS URL, you can mint your NFT on-chain following the ERC-721 standard.

How to mint an NFT (ERC-721)

In this section, we will walk you through how to mint a one-of-one (i.e., unique) NFT for demonstration purposes. We will follow the ERC-721 standards and use Remix IDE along with the IPFS URL of the metadata uploaded to NFT.Storage.

Here’s how to mint an ERC-721 NFT using Remix IDE:

  1. Create a .sol file.
  2. Copy and paste the ERC-721 code into your Remix editor:
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC721, ERC721URIStorage, Ownable {

    constructor() ERC721("MyToken", "MTK") {}

    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 _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);

    }

}
  1. Change the name “MyToken” and the symbol “MTK” to your desired name and symbol.
  2. Compile the code by clicking the Solidity Compiler tab, followed by the Compile button.
  3. Go to the Deploy & Run Transactions tab and select “MyToken” from the dropdown.
  4. Click the Deploy button.
  5. Once deployed, expand the deployed contract and copy the contract address.
  6. Go back to the Solidity Compiler tab, and select the “MyToken” contract from the dropdown.
  7. Click on the “safeMint” function.
  8. Fill in the “to” field with your Ethereum address, the “tokenId” field with the desired ID of your NFT, and the “uri” field with the metadata IPFS URL you copied from NFT.Storage.
  9. Click on the “transact” button to mint your NFT.

Congratulations – you have successfully minted your own ERC-721 NFT!

+ posts

If you'd like to keep up with BlueLabel, enter your email to get our monthly newsletter

Subscribe

* indicates required