hey hey hey!
Hello everyone 0Xlive is here 😃
in this tutorial we will talk about CRC721 ,NFT and how to deploy our NFT on CSC using hardhat
NFT
NFT stands for non-fungible token.which is a one-of-a-kind digital resource that uses blockchain technology. The first NFTs were made in 2017 before the term even existed. Soon after, crypto-kitties and crypto-sharks instituted the term on the market and even normalized Smart Contracts.
non-fungible means unique and unexchangeable.NFTs are unique; each one is different. Every single token has unique characteristics and values.
CRC721
CRC-721 is non-fungible standard on CSC network. it is same as ERC-721.
“ERC-721 is a free, open standard that describes how to build non-fungible or unique tokens on the Ethereum blockchain. While most tokens are fungible (every token is the same as every other token), ERC-721 tokens are all unique.“https://erc721.org
ERC-721 is an open standard that describes how to build Non-Fungible tokens on EVM (Ethereum Virtual Machine) compatible blockchains; it is a standard interface for Non-Fungible tokens
Lets get started 😃
first of all we need to make a directory for our project
mkdir crc721
and then change directory to crc721 and init a project with npm
cd hardhat-tutorial
npm init --yes
and now we are going to install hardhat
npm install --save-dev hardhat
when installation completed run hardhat using npx
npx hardhat
choose"Create a basic sample project”
and enter yes for all 😃
note : it will ask you about hardhat-waffle , ethereum-waffle and hardhat-ethers
, by the way you can install them manually using following instruction:
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
and press enter for all
we would use openzeppelin library to make it easy
npm install @openzeppelin/contracts
we would write some code in the NFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
// Import the openzepplin contracts
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
// GameItem is ERC721 signifies that the contract we are creating imports ERC721 and follows ERC721 contract from openzeppelin
contract nft is ERC721 {
constructor() ERC721("simple nft", "NFT") {
// mint an NFT to yourself
_mint(msg.sender, 1);
}
}
let’s break the code above
// SPDX-License-Identifier: MIT
in the first line of code we set MIT as license in machine readable format
pragma solidity ^0.8.10;
it says to compiler to compile with version 0.8.10
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
we have imported ERC721.sol from openzeppelin library
contract nft is ERC721 {
constructor() ERC721("simple nft", "NFT") {
// mint an NFT to yourself
_mint(msg.sender, 1);
}
}
the main part is here.in solidity , our code must be under contract
we set simple nft as name and NFT as symbol for our contract
now its time to compile!
npx hardhat compile
If there is no error , we will go for deploy :)
Hardhat Configuration
Firstof all, create a new file named run.js
under scripts
folder
put this code in run.js:
const { ethers } = require("hardhat");
async function main() {
/*
A ContractFactory in ethers.js is an abstraction used to deploy new smart contracts,
so nftContract here is a factory for instances of our GameItem contract.
*/
const nftContract = await ethers.getContractFactory("NFT");
// here we deploy the contract
const deployedNFTContract = await nftContract.deploy();
// print the address of the deployed contract
console.log("NFT Contract Address:", deployedNFTContract.address);
}
// Call the main function and catch if there is any error
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
now , hardhat.config.json should be like this:
require("@nomiclabs/hardhat-waffle");// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();for (const account of accounts) {
console.log(account.address);
}
});module.exports = {
solidity: "0.8.10",
networks: {
csc: {
url: "https://testnet-rpc.coinex.net",
accounts: ["YOUR-PRIVATE_KEY"],
}
}
};
to deploy the contract , in your terminal type:
npx hardhat run scripts/run.js --network csc
Congratulation 🥳
you deployed your first NFT on CSC network
we will go further and making some cool stuff
Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing