【How2Do】5 Steps to Create an NFT with Smart Contract
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.
- Install Metamask
- Upload your image on IPFS via Pinata
- Write Solidity Smart Contract with Openzeppelin wizard
- Remix to Deploy Solidity Smart Contract
- 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.
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.
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.
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.
- copy the file IPFS CID on your asset.
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.
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 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.
- Switch the tab to ERC721
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.
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.
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.
Remix is a web app that allows you to develop, compile, and deploy Solidity Smart Contract without downloading.
Compile contract
Once your smart contract is written, you can compile it by taking the following steps:
- Make sure the compiler version is the same or larger than the pragma version.
- Click on the compile button.
- If compile successfully, you will see the green tick and ready to deploy it on blockchain.
Deploy contract
- Switch to the “Deploy & Run Transactions” tab
- 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.
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”.
4. If everything is ready, click on the “Deploy” button. Review the transaction information in MetaMask and confirm it.
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.
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:
- to — add your wallet address to the field and you will get the token after mint.
- tokenId — enter any number value (you can start with 0, each token id is non-repeatable)
- uri — add your IPFS URL, which we mentioned in step2 Pinata. (metadata)
Please enter your IPFS URL in the format ipfs://<metadata file CID>
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.
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
- https://ethereum.org/en/nft/
- https://ethereum.org/zh-tw/developers/tutorials/how-to-write-and-deploy-an-nft/
- https://www.prestigeonline.com/th/pursuits/tech/7-nft-projects-the-world-is-talking-about-right-now
- https://www.oberlo.com/blog/how-to-make-nft
ERC-721
- https://academy.binance.com/en/glossary/erc-721
- https://medium.datadriveninvestor.com/whats-the-nft-erc-721-token-standard-875160ca798a
- https://medium.com/geekculture/mint-an-nft-and-erc-721-smart-contract-easy-step-by-step-4fafff151fbe
Create
- https://codeforgeek.com/how-to-create-your-own-nft-in-5-steps/
- https://moralis.io/how-to-create-your-own-nft-in-5-steps/
- https://ethr.me/deploy-an-ethereum-smart-contract-in-3-minutes-ccb8f8f22598
- https://medium.com/pinata/how-to-create-layer-2-nfts-with-polygon-and-ipfs-aef998ff8ef2
- https://betterprogramming.pub/how-to-create-an-nft-contract-without-coding-skills-968d3fc37f5e
IPFS
- https://medium.com/coinmonks/deploying-an-ipfs-backed-nft-47ff6ff0c0
- https://medium.com/coinmonks/upload-to-ipfs-using-pinata-bf59ce265ab5
OpenZeppelin
- https://moralis.io/what-is-openzeppelin-the-ultimate-guide/
- https://betterprogramming.pub/7-openzeppelin-contracts-you-should-always-use-5ba2e7953cc4
- https://blog.logrocket.com/openzeppelin-secure-smart-contracts/
- https://docs.moonbeam.network/builders/build/eth-api/dev-env/openzeppelin/contracts/
Contents distributed by Learn.Block6.tech
👉 Telegram — Fresh ideas
👉 Twitter — Latest articles