top of page

#1 How to Mint an NFT

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

  1. Create the app on Alchemy

  2. 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)

  1. Open VScode and create a new file ProjectName.sol inside the contract folder

  2. Write the smart contract

  3. If you use openzeppelin as a library THEN you have to install npm install @openzeppelin/contracts

  4. Install the dotenv package in the project directory: npm install dotenv --save

  5. 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"

  1. 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

  2. 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

  1. Compile the contract to check that all is good npx hardhat compile

  2. Write the deploy script, navigate to the scripts folder and create a new file called deploy.js, adding the code

  3. Deploy the contract npx hardhat --network goerli run ./scripts/deploy.js

  4. All great: Contract deployed to address: 0x81c587EB0fwhatever 🙌

  5. Go to https://network_test.etherscan.io/ and search for the contract address

  6. 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.

  7. Install npm install @alch/alchemy-web3 and Create a project-name.js inside the script directory

  8. 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

  9. Use Pinata to store the NFT asset and metadata to ensure the NFT is truly decentralized

  10. Create and upload to Pinata the file nft-metadata.json (all the information regarding the NFT asset file.

  11. 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)

  1. 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

  1. Sign the transaction with the Private key

  2. Get its hashcode from Pinata and pass the following as a parameter to the function mintNFT adding "ipfs://

  3. Run: node scripts/project-nft.js to deploy the NFT and you will see the hash of your transaction is: 0x……

  4. Check Alchemy's Mempool to view the status of the transaction!

  5. Done ✅ You’ve now deployed AND minted with an NFT on the Ethereum blockchain 🎉

  6. 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


bottom of page