【How2Do】5 Steps to Create an NFT with Smart Contract

Jincoco
BLOCK6
Published in
9 min readJun 3, 2022

Whether you’re a blockchain developer or not, you must have heard of the “NFT”, which is growing fast and exploded in popularity recently. Here are some explanations and will show the way to publish your own NFT (ERC-721 Token) on the Ethereum blockchain and list it on the Opensea market!

In this article, we will be going to creating and deploying an ERC-721 Smart Contract on the Rinkeby test network by using Metamask, coding Solidity Smart Contract with Remix IDE, Pinata to upload your asset on IPFS, Opensea, but don’t worry we will lead you to step by step.

  1. Install Metamask
  2. Upload your image on IPFS via Pinata
  3. Write Solidity Smart Contract with Openzeppelin wizard
  4. Remix to Deploy Solidity Smart Contract
  5. Find Your NFT on OpenSea Testnet

Before we go on, here are some of the general terms you need to know. you can just pass it that doesn’t affect our final purpose.

What is NFT?

Non-Fungible Tokens, NFT are digital assets with a unique identity kept and verified on blockchain, we can use these tokens to represent ownership of unique items. It is non-fungible, which means it can’t be exchanged for another asset like Bitcoin or ETH. Most of them include images, videos ,music , and GIFs.

What is Ethereum?

Ethereum is a platform based on blockchain technology, its native cryptocurrency is called ether, or ETH. Ethereum supports “Turing Completeness” which is the biggest difference from Bitcoin, with this you can execute not only transactions but also some programming logic by deploying something like dApps, or Smart Contract.

What is ERC-721?

Ethereum Request for Comments, not technology or framework, provides technical guidance for developers to build Smart Contracts, ERC-721 is a token standard on Ethereum blockchain. different from ERC-20 tokens that ERC-721 tokens are non-fungible. This means that each token is unique and as a result, not interchangeable.

1. Install Metamask

Metamask

MetaMask is a browser extension designed to make accessing Ethereum’s Dapp ecosystem easier. It also serves as a wallet for holding ERC-20 tokens allowing users to access services built on the network via the wallet.

At first, we need to have a Metamask wallet on your browser, this is the first step to saying hello to Ethereum.

Download here : https://metamask.io/

Get Rinkby test Ether

Open this Rinkeby faucet https://rinkebyfaucet.com/ and switch your wallet Metamask to the Rinkby testnet.

switch to the Rinkby testnet

Copy your wallet address and paste it to the input, click “Send Me ETH” to get some test Ether, we will need it to pay the gas fees on deploying Smart Contract later.

get some test Ethers

2. Upload your image on IPFS via Pinata

IPFS

InterPlanetary File System, is a protocol and peer-to-peer network for storing and sharing data in a distributed file system …

Get a Pinata account

We can upload files to IPFS by using a terminal or IPFS desktop, but this time we will use “Pinata” is easier to get started and manage your file on IPFS. By creating an account using free plan we will have 1GB of storage.

Visit the Pinata website https://www.pinata.cloud/ and click “Try for free” to get an account.

Upload File

click upload > file > select file, when you upload it you’ll see it in the Pin Manager table.

upload > file > select file
upload finished

We’ve uploaded the image, next we have to upload “metadata” JSON file, which allows applications like OpenSea to pull data from NFT and display them.

  1. copy the file IPFS CID on your asset.
file IPFS CID

2. copy the following code to any text editor, write name description you want, and replace the image from the asset you uploaded previously, the format like this ipfs://asset_CID. Remember to save that file with anyname.json.

{
"name": "My NFT",
"description": "This is my NFT",
"image": "ipfs://QmQ8u3Tt9xmm7NoCarjuZRFsWX86Y2KRNZq8JQEVGA9WG7"
}

3. Once you’ve done, go back to the Pinata and upload that JSON file. We will use it later when we mint our NFT.

metadata file

3. Write Solidity Smart Contract with Openzeppelin wizard

“A library for secure smart contract development. Build on a solid foundation of community-vetted code.” — OpenZeppelin.com

https://docs.openzeppelin.com/contracts/4.x/wizard

OpenZeppelin offers open source Contracts repository, with the ERC standards for Ethereum-based tokens, developers can be used in many types of projects, to reduce the risk of security.

Now we have “Contracts Wizard” provided by OpenZeppelin, this is the easiest way to write a smart contract using OpenZeppelin code, so we don’t need to code much. The web application allows you to generate a Smar Contract template only with several clicks.

Openzeppelin Contracts Wizard

Openzeppelin Contracts Wizard supports the following ERC standards:

  • ERC-20 — a fungible token standard that follows EIP-20. Fungible means that all tokens have the same value and are interchangeable, such as fiat currencies.
  • ERC-721 — a non-fungible token contract that follows EIP-721. Non-fungible means that each token is different and unique. An ERC-721 token can represent ownership of that unique item, whether it is a collectible item in a game, images, music, and so on.
  • ERC-1155 — a multi-token contract that follows EIP-1155. the ERC-1155 token can do the same functions as an ERC-20 and ERC-721 token, and even both at the same time.

Create a Contract

In this time, we will create an NFT by using ERC-721 standards, it’s easier to get started and understandable.

  1. Switch the tab to ERC721
Click the tab switch to erc721, and set the name you want.

2. Check the Features we need

  • Mintable — Allow accounts will be able to “Mint”(make) new tokens.
  • URI Storage — Allows updating token URIs, you can attach images for NFT.
check “Mintable”, “URI Storage”

3. Edit and copy to Remix

Now that we have set up contract with all the settings and features, we are going to deploy it with Remix. To do this, click the “Open in Remix” button, and it will auto-copy and paste the code into contract.

it will auto copy contract to Remix

4. Remix to Deploy Solidity Smart Contract

Remix

Remix IDE allows developing, deploying and administering smart contracts for Ethereum like blockchains. It can also be used as a learning platform.

https://remix.ethereum.org/

Remix is a web app that allows you to develop, compile, and deploy Solidity Smart Contract without downloading.

Remix IDE

Compile contract

Once your smart contract is written, you can compile it by taking the following steps:

  1. Make sure the compiler version is the same or larger than the pragma version.
  2. Click on the compile button.
  3. If compile successfully, you will see the green tick and ready to deploy it on blockchain.
Compile contract

Deploy contract

  1. Switch to the “Deploy & Run Transactions” tab
  2. First, change the environment to “Injected Web3”. This will use MetaMask’s injected provider, and the contract will be deployed on the network where MetaMask Connects. When you select it MetaMask will pop-up and ask Remix to connect to your wallet.
connect the wallet

3. Ensure you select the correct contract from the list before you deploy. In this case, the contract “HelloDoge” is the same as my settings name “HelloDoge”.

select the correct contract

4. If everything is ready, click on the “Deploy” button. Review the transaction information in MetaMask and confirm it.

confirm the transaction

5. After the transaction has been confirmed, the contract has successfully been deployed on the blockchain, and you will see it under “Deployed Contracts” on the left.

the contract on the blockchain | https://rinkeby.etherscan.io

Let’s make the contract to a real NFT!

6. Mint NFT token

Find the “SafeMint” function in the Deployed Contracts section and expand it to add the following details:

  1. to — add your wallet address to the field and you will get the token after mint.
  2. tokenId — enter any number value (you can start with 0, each token id is non-repeatable)
  3. uri — add your IPFS URL, which we mentioned in step2 Pinata. (metadata)
    Please enter your IPFS URL in the format ipfs://<metadata file CID>
copy the metadata file’s CID and the format is ipfs://xxx…

Finally, click transact and confirm your transaction on Metamask!

Well done, Your own NFT is minted!

5. Find Your NFT on OpenSea Testnet

OpenSea

The world’s first and largest digital marketplace for crypto collectibles and non-fungible tokens (NFTs). Buy, sell, and discover exclusive digital items.

https://testnets.opensea.io (Testnet)

Now we can check our own NFT on OpenSea and it has a test version supporting Rinkeby test net. First, we should connect MetaMask wallet to the OpenSea.

connect wallet to the OpenSea

Here is your NFT! You can sell it or do anything you want.

That all, after following these five steps, we have successfully created an ERC-721 NFT with these wonderful tools like MetaMask, Pinata, OpenZeppelin, and Remix. Moreover, we list our NFT on the OpenSea, which can be traded.

Thank you for watching, and I hope this article helped you get a better understanding of NFT. Have fun!

Translation tools

Reference

NFT

ERC-721

Create

IPFS

OpenZeppelin

Contents distributed by Learn.Block6.tech

👉 Telegram — Fresh ideas

👉 Twitter — Latest articles

👉 LinkTr.ee

--

--