We are happy to share with you the steps to build an NFT with smart contracts 🧠
Please be aware we are using this blog post to simply share information and methods that are beneficial for beginners. We used the below method for fun back in May the 30th 2022. We used solidity programming and this is our chance to help new developers to get in touch with this useful technology. The Web3 community and we have advanced a lot since May but this doesn't mean we should forget other people that are just now approaching this world.
Feel free to ask questions we will try to answer in a relatively short time, please just bear with us because our team is really busy making the Property World Market a better place to invest in a very easy way 🎉.
We used Goerli as a Network test, Alchemy as a Dashboard to view our transactions on the network, Pinata to upload our smart contract JSON (because inside the transaction is allowed only strings, efficiency reason), meta information, and file, and at the end 3rd doc, will show the NFT file inside the Metamask account. We used FaucETH to send fake ETH for testing and used Hardhat as a development environment to compile, deploy, test, and debug your Ethereum software.
Below are the steps To automate the creation of NFT and the visualisation of those inside the Metamask Wallet
Create the app on Alchemy
Create the app folder (ProjectName) and
npm init THEN npm install --save-dev hardhat THEN npx hardhat (Create a basic sample project hardhat.config.js)
Open VScode and create a new file ProjectName.sol inside the contract folder
Write the smart contract
If you use openzeppelin as a library THEN you have to install npm install @openzeppelin/contracts
Install the dotenv package in the project directory: npm install dotenv --save
Create the .env and put it inside Metamask private key and alchemy api key
API_URL="https://eth-goerli.alchemyapi.io/v2/api_key"
PRIVATE_KEY="your-metamask-private-key"
Install Ethers.js is a library that makes it easier to interact and make requests to Ethereum npm install --save-dev @nomiclabs/hardhat-ethers ethers@^5.0.0
Update HARDHAT.CONFIG.JS with the yourtestnetname
Changed the name of the project (not starting with a number)
Gave project name and contract the same name
Put the same name project for the constructor and the variable passed to the constructor
Compile the contract to check that all is good npx hardhat compile
Write the deploy script, navigate to the scripts folder and create a new file called deploy.js, adding the code
Deploy the contract npx hardhat --network goerli run ./scripts/deploy.js
All great: Contract deployed to address: 0x81c587EB0fwhatever 🙌
Go to https://network_test.etherscan.io/ and search for the contract address
Use alchemy to look at the new NFT smart contract deployed on ETH blockchain, “Minting an NFT” is the act of publishing a unique instance of your ERC-721 token on the blockchain.
Install npm install @alch/alchemy-web3 and Create a project-name.js inside the script directory
Use your Contract ABI to interact to the smart contract by adding const contract = require("../artifacts/contracts/South.sol/South.json") inside project-name.js to parse out the content of the contract ABI
Use Pinata to store the NFT asset and metadata to ensure the NFT is truly decentralized
Create and upload to Pinata the file nft-metadata.json (all the information regarding the NFT asset file.
Interact with our contract:
by adding an instance inside project-nft.js using the WEB3:
const contractAddress = "0x81c587EB0fE773404c42c1d2666b5f557C470eED"
const nftContract = new web3.eth.Contract(contract.abi, contractAddress) contract method to create the contract using the ABI and the contract address (took in Etherscan)
Create and Send transactions to Ethereum chain
Use the public ethereum account address to get the account nonce. Update the .env file with the Ethereum public key. The nonce specification is used to keep track of the number of transactions sent from your address — which we need for security purposes and to prevent replay attacks.
Create the transaction
Sign the transaction with the Private key
Get its hashcode from Pinata and pass the following as a parameter to the function mintNFT adding "ipfs://
Run: node scripts/project-nft.js to deploy the NFT and you will see the hash of your transaction is: 0x……
Check Alchemy's Mempool to view the status of the transaction!
Done ✅ You’ve now deployed AND minted with an NFT on the Ethereum blockchain 🎉
View your new minted NFT on Metamask on Mobile (doesn't work on desktop for now)
Select the network in where you minted the NFT
Select the NFT Tab
Press Import NFT
Add the smart contract address and the ERC-721 token ID of your NFT (find those on Etherscan page inside transaction details)
Refresh the page and ✅
I want to thank the UK company SAL Digital ltd for this collaboration. Has been a fantastic journey so far. Well, Done team 🙌
Alessio
Commenti