# Token Series: Build, Deploy & List ERC721 token on OpenSea

The technology that enables NFTs is one of the most important reasons they explode.

Tokens are practically impossible to discuss without mentioning crypto and Web3. Furthermore, tokens are categorized into fungible and non-fungible tokens (NFTs).

This post will teach us how to build and deploy the ERC721 (NFT) token and get listed on OpenSea.


## What is ERC721 Token?

The ERC-721 sets a standard for NFT, which means that this form of Token is unique and may have a different value than another Token from the same Smart Contract, for example, due to its age, rarity, or even its aesthetic.

ERC-721 tokens and NFTs can represent ownership of a wide range of natural and digital assets, making them versatile and dynamic. They can represent virtual collectibles like CryptoKitties, tangible goods like houses, and negative value assets like debt.

It has features like transferring tokens from one account to another, getting an account's current token balance, finding the owner of a specific token, and seeing the entire token supply on the network.

We'll utilize [IPFS](https://ipfs.io/), a peer-to-peer file storing and distributed system, to host our NFT art and create a metadata file before developing our NFT contract.


## What is IPFS

IPFS is a distributed file, website, application, and data storage and retrieval system.

IPFS is a distributed file system. Git, a version control program, is one of the most widely used decentralized systems. Every developer who cloned a repository has a copy of the complete repository, including the history, on their computer, making Git a distributed system. 

Any reproduction of the central repository can be used to restore it if lost, adopting the distributed notion to store and retrieve files.

## Upload Metadata to IPFS

Follow the installation guide in the IPFS documentation to download and install [IPFS CLI](https://docs.ipfs.io/how-to/command-line-quick-start/#prerequisites) for our operating system.

After successful installation, we will go through the following steps to host our image and metadata.

###  Creating IPFS repository

We will use the following command to create the IPFS repository.

```
ipfs init
```

### Starting the IPFS daemon

We will start the IPFS daemon in a separate terminal using the following command.

```
ipfs daemon
```

We should see something similar to what we have below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652614022439/DYIiXyJcc.png align="left")

Let us head over to the URL we copied above. We should see something similar to what is shown below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652614178771/_0knAgnK5.png align="left")

### Adding an image to IPFS 

This section will add an image(s) `my-art.png` to IPFS directly on our browser. 

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652614517503/URuCHZH4o_.png align="left")

We navigate to the `FILES` tab in the image above to upload any image of our choice. After uploading we can copy the `CID` - `QmbaYgLSYkFqvUJ6Dh393vkByAfJFwpxoUgWTDshQdV452` as shown below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652614796127/xtIANBlCW.png align="left")

Let us copy the link(URL) provided by IPFS [https://ipfs.io/ipfs/QmbaYgLSYkFqvUJ6Dh393vkByAfJFwpxoUgWTDshQdV452](https://ipfs.io/ipfs/QmbaYgLSYkFqvUJ6Dh393vkByAfJFwpxoUgWTDshQdV452?filename=my-art.png)

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652615209104/vpMm_Vj5E.png align="left")

Copy the URL.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652615250572/LzaqKH_mZ.png align="left")

Opening the link provided in the browser, we should have our beautiful art displayed on our browser, as shown below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652616498367/2U6i3oDLh.png align="left")

> Note: It may take several minutes(approx 20min or less) before our art gets rendered on the browser for the first time. Be patient :(

**Other decentralized storage systems, such as Filebase, Pinata, and others, can be used to bypass the entire process of waiting for minutes.**

*Checkout these tutorials*
- [How to Use IPFS Desktop With Pinata](https://knowledge.pinata.cloud/en/articles/5508876-how-to-use-ipfs-desktop-with-pinata)
- [Uploading your NFT content to IPFS leveraging Pinata](https://allcode.com/upload-nft-content-to-ipfs-via-pinata/)
- [Filebase: Building Web3 with Web3](https://blog.ipfs.io/2022-04-14-filebase/)

### Adding Metadata to IPFS

Create a JSON file `my-art.json` using the following command.

```
touch my-art.json
```

Let us update it with the following data.

```
{
     "name": "My Art",
     "description": "This image shows my cute art.",
     "image": 
     "https://ipfs.io/ipfs/QmbaYgLSYkFqvUJ6Dh393vkByAfJFwpxoUgWTDshQdV452"
}
```
The image field should contain the art URL we created earlier.

Next, we will add it to IPFS by uploading it the way we uploaded the image in the previous step.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652616719633/QL-ACekCi.png align="left")

> We need to wait some minutes(approx 20 min or less) for us to preview the URL on the browser via
[https://ipfs.io/ipfs/QmYSyNbXbYSaJbgY8BG5tXQmduxA7YCeL8upsoEquF345V](https://ipfs.io/ipfs/QmYSyNbXbYSaJbgY8BG5tXQmduxA7YCeL8upsoEquF345V?filename=my-art.json)

Once it's ready, we will have something similar to what we have below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1653409497029/EHUx_mnRe.png align="left")


## Build an ERC721 Token Smart Contract with Solidity using the remix IDE

We'll learn how to utilize [https://remix.ethereum.org/](https://remix.ethereum.org/), a free, easy-to-use IDE with a solidity-compatible IntelliJ feature and decent compile-time errors, to build and deploy an ERC721 NFT Smart Contract.

Next, we will navigate to the [Remix](https://remix.ethereum.org/) site and create a new file called `MyArt.sol` as shown below.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652617260353/KmYoEcaeF.png align="left")

Let's update the `MyArt.sol` file with the following code snippet.

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

import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.6.0/utils/Counters.sol";

contract Wizard is ERC721, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("MyArt", "MAT") {}

    function _baseURI() internal pure override returns (string memory) {
        return "<Add the metadata URL here>";
    }

    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
    }
}

```

In the code snippet above, we:

- Imported the OpenZeppelin ERC721 contract, Ownable, and Counter
- Initialize the Token, inheriting from the ERC721.sol contract
- Declared a new contract called `MyArt,` using the Solidity keyword contract, while inheriting the ERC721 OpenZeppelin's contract using the `is` keyword.
- Created a function that returns our `_baseURI`
- Created a function `safeMint` that allows users to mint `NFT safely.`

Next, we will compile our contract and get it ready for deployment.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652617895408/PbTqfkznO.png align="left")


## Deploy ERC721 Token (NFT) Smart Contract

We will deploy our smart contract to the Polygon Mumbai testnet in this step. We may deploy to any of our chosen chains and are not limited to the Mumbai testnet.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652618063077/uS70laHa7.png align="left")

Next, we will select the contract to deploy.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652618171216/kqRnntWDA.png align="left")

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652618413421/RracK7q3h.png align="left")

We will see a prompt to approve the transaction.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652619688337/J-aPWQbAH.png align="left")

Verifying on Polygon scan [here](https://mumbai.polygonscan.com/tx/0xc0894901422733beb2a579b989b196849cc0cec8dbe2570d13b78b897c2b08eb)

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652619789712/iMrbwIiTz.png align="left")

After deploying, let us mint a copy of the `NFT.`

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652619991572/pRzbf3eEd.png align="left")

Approve the transaction via the Metamask pop-up.

Next, we can check the token balance of the address that just minted the NFT.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652620254293/EEP0HNtlr.png align="left")

Voila 🥳

## Verify / List ERC721 Token on OpenSea

Super excited we made it to this section. 

Next, we will `copy` the contract hash.

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652620398395/JW8sUwhI7.png align="left")

We can now list our NFT on the OpenSea testnet using the Mumbai chain. Let's head over to [https://testnets.opensea.io/get-listed](https://testnets.opensea.io/get-listed).

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652619100763/bC7C0lxUW.png align="left")

![Build, Deploy & List ERC721 token on OpenSea](https://cdn.hashnode.com/res/hashnode/image/upload/v1652620605420/GyXM-Qocc.png align="left")

We will be redirected to the collection page to view our NFT.

> For some reason, OpenSea takes reasonable time for the NFT to display on their platform, but the project is complete. ;)

## Conclusion

This post addresses how to build, deploy, and list the ERC721 on OpenSea step by step as part of the token series I started earlier. Watch this space for the upcoming ones.

I'd love to connect with you at [Twitter](https://twitter.com/olanetsoft) | [LinkedIn](https://www.linkedin.com/in/olubisi-idris-ayinde-05727b17a/) | [GitHub](https://github.com/Olanetsoft) | [Portfolio](https://idrisolubisi.com/)

See you in my next blog article. Take care!!!
