This beginner-friendly course will help you build a Web3 mint website where you can sell NFTs. This tutorial will mainly focus on non-fungible tokens (NFTs). It will guide you through creating a web application that will help you mint your own unique digital assets on the Ethereum blockchain. To follow this tutorial, you need some basic understanding of popular technologies such as React, Ethers, Hardhat, and Web3. These technologies will help you to develop the mint website from the ground up.
This tutorial contains step-by-step information on everything you need to know about NFT, so you don’t have to be a seasoned professional. Even if you are just curious about NFTs or you want to start your own mining platform, this guide has enough information to bring your vision to reality.
So, without further ado, let’s get started.
To kick-start this project, you will need to prepare your system. The first step is to install Node.js and npm (Node Package Manager) on your system. Although there is no skill set required for this tutorial, a basic understanding of HTML, CSS, and JavaScript will help you navigate it seamlessly.
A mint website is a web application that helps the user create their own NFTs. This website contains a basic user interface. Through this interface, the user interacts with the application and starts creating a new unique NFT.
Within this tutorial, the Mint website will be developed using basic technologies like React, Ethers, Hardhat, and Web3. The website will have a button in its interface. The user can simply click the button and get to mint their NFT.
Clicking this button will simply enable the website to connect with the Ethereum network. Consequently, this will trigger the user to connect their Ethereum account and commit a transaction to a smart contract that is running on the network. As a result of this process, smart contracts will mint the NFT and allocate it to the user.
The website will offer a very simple, aesthetic, and user-friendly interface to the user for creating the NFTs. Each NFT allocated will be a unique digital asset with verifiable ownership, so it will have a much better worth. For an enhanced user experience, the website can be customized with additional features. The project has a scope for further improvement based on the requirements of the user or the owner.
It is a JavaScript library offering a very consistent yet simple interface that can be used to interact with Ethereum and other similar networks. Ethers allow developers to write code to interact with smart contracts, commit transactions, and provide other financial services.
It is a development environment used for Ethereum smart contracts. Hardhat offers a set of essential tools and other similar functions for compiling, deploying, testing, and debugging smart contracts. It is a very important yet very extensible development environment that is used for supporting other similar frameworks i.e. React and Truffle.
Within the blockchain, smart contracts play an essential role. A smart contract is an automated contract with essential terms and conditions of agreement. It is written directly into the code and cannot be changed once deployed.
Smart contracts are deployed via a blockchain network and can automatically commit all the terms and conditions that are added to the contracts.
Deploying smart contracts to a test network like Rinkeby is easy. Here is a step-by-step process that will help you deploy a smart contract to a test network:
Start by configuring the deployment script with the desired network settings.
Now, you can execute the deployment script using the command npm run deploy.
This command will trigger the compilation process, and you will be able to execute the smart contract for your desired network. Eventually, the contract's address will be logged in the console.
The token identifier is an exclusive identifier that denotes the metadata linked with a non-fungible token (NFT). The Token URI contains all the information on the NFT, including the name, description, image, and other attributes.
This token can be saved on-chain, or it can also be hosted off-chain, depending on the preference. The function of this token is to store and then deliver detailed information about the NFT when needed.
npx create-react-app mint-website
cd mint-website
npm install ethers hardhat @nomiclabs/hardhat-ethers web3
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract NFT is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("MyNFT", "NFT") {}
function mintNFT(address recipient, string memory token URI) public returns (uint256) {
_tokenIds.increment();
uint256 newTokenId=_tokenIds.current();
_mint(recipient, newTokenId);
_setTokenURI(newTokenId, tokenURI);
return newTokenId;
}
}
const hre=require("hardhat");
async function main() {
const NFT=await hre.ethers.getContractFactory("NFT");
const nft=await NFT.deploy();
await nft.deployed();
console.log("NFT contract deployed to:", nft.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"deploy": "hardhat run scripts/deploy.js --network "
}
To customize this code, you can replace with your specified network (e.g., "rinkeby" for the Rinkeby test network).
import React, { useState } from "react";
import { ethers } from "ethers";
import "./App.css";
function App() {
const [minted, setMinted] = useState(false);
const [loading, setLoading] = useState(false);
const mintNFT=async () => {
try {
setLoading(true);
// Connect to Ethereum provider
const provider=new ethers.providers.Web3Provider(window.ethereum);
// Request access to user's Ethereum account
await window.ethereum.enable();
// Get the signer (current user)
const signer=provider.getSigner();
// Load the smart contract
const contractAddress="CONTRACT_ADDRESS"; // Replace with your deployed contract address
const contractABI=[
// Add the contract's ABI here
];
const contract=new ethers.Contract(contractAddress, contractABI, signer);
// Call the mintNFT function on the contract
const tx=await contract.mintNFT(signer.getAddress(), "TOKEN_URI");
// Wait for the transaction to be mined
await tx.wait();
setMinted(true);
} catch (error) {
console.error(error);
} finally {
setLoading(false);
}
};
return (
{minted ? (
Congratulations! Your NFT has been minted.
) : (
{loading ? "Minting..." : "Mint NFT"}
)}
);
}
export default App;
.
App {
text-align: center;
margin-top: 100px;
}
button {
padding: 10px 20px;
font-size: 18px;
background-color: #5cb85c;
color: #fff;
border: none;
cursor: pointer;
border-radius: 4px;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
npm start
Congrats! You just launched your Web3 mint website using React, Ethers, Hardhat, and Web3.