Ethereum NFT Minting and Display: A Step-by-Step Guide

·

Creating and showcasing Non-Fungible Tokens (NFTs) on the Ethereum blockchain has become a cornerstone of digital ownership in Web3. Whether you're an artist, developer, or blockchain enthusiast, understanding how to mint and display an NFT empowers you to participate in this decentralized ecosystem. This comprehensive guide walks you through the full process of minting an ERC-721 NFT using tools like Alchemy, Web3.js, IPFS, and MetaMask—all while leveraging the Goerli testnet for risk-free experimentation.

Core Keywords


Installing Web3.js for Ethereum Interaction

To interact with the Ethereum network programmatically, we use Web3.js, a powerful JavaScript library that enables communication with Ethereum nodes. In this tutorial, we’ll use Alchemy Web3, an enhanced version offering improved reliability, automatic retries, and WebSocket support.

Run the following command in your project’s root directory to install it:

npm install @alch/alchemy-web3

This sets the foundation for sending transactions, querying blockchain data, and interacting with your deployed smart contract.

👉 Learn how to connect your dApp to Ethereum with advanced Web3 tools.


Creating the Mint Script: mint-nft.js

In your project’s scripts folder, create a new file named mint-nft.js. This script will handle the entire NFT minting process. Begin by loading environment variables and initializing the Alchemy Web3 provider:

require("dotenv").config();
const API_URL = process.env.API_URL;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(API_URL);

Using dotenv ensures your sensitive credentials remain secure and externalized from your codebase.


Retrieving the Contract ABI

The Application Binary Interface (ABI) is essential for interacting with your smart contract. When you compile a Solidity contract using Hardhat, it automatically generates a JSON artifact containing the ABI.

Add this line to load your contract’s ABI:

const contract = require("../artifacts/contracts/NewNFT.sol/NewNFT.json");
console.log(JSON.stringify(contract.abi));

You can verify the output by running:

node scripts/mint-nft.js

This prints the ABI to the console, confirming correct setup.


Storing NFT Metadata Using IPFS

Every NFT relies on metadata—JSON data defining its name, description, image, and attributes. To ensure decentralization, this metadata should be stored off-chain in a distributed system like IPFS (InterPlanetary File System).

We’ll use Pinata, a user-friendly IPFS gateway, to host our metadata:

  1. Log into Pinata and upload your image file.
  2. Copy the returned CID (Content Identifier).
  3. Create a local nft-metadata.json file referencing the IPFS image URL:
{
 "name": "Caesar",
 "description": "Very powerful programmer ape.",
 "image": "ipfs://QmXectapuW3yBCWwgjf78h3Dqdo2zpD5qaq4zXb63qXbp9",
 "attributes": [
  { "trait_type": "Breed", "value": "Ape" },
  { "trait_type": "Eye", "value": "Glasses" },
  { "trait_type": "Face", "value": "Smiled" }
 ]
}
  1. Upload this JSON file to Pinata as well and note its CID.

Now your metadata is permanently stored on IPFS—immutable and decentralized.


Instantiating the Smart Contract

To interact with your deployed ERC-721 contract, instantiate it using its address and ABI:

const contractAddress = "0x094180BBc8f5e8e9697C0F633D4004e3ecea6510";
const nftContract = new web3.eth.Contract(contract.abi, contractAddress);

Ensure this address matches the one from your previous deployment on the Goerli testnet.


Configuring Environment Variables

Securely manage your credentials using a .env file:

API_URL="https://eth-goerli.alchemyapi.io/v2/your-api-key"
PRIVATE_KEY="your-metamask-private-key"
PUBLIC_KEY="your-metamask-public-address"

Never commit this file to version control. It allows your script to sign transactions using your wallet’s private key without exposing it in code.


Building and Signing the Transaction

Step 1: Constructing the Transaction

Create an async function mintNFT(tokenURI) that builds the transaction:

async function mintNFT(tokenURI) {
 const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, 'latest');

 const tx = {
  from: PUBLIC_KEY,
  to: contractAddress,
  nonce: nonce,
  gas: 500000,
  data: nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI(),
 };
}

Here:

Step 2: Signing the Transaction

Use your private key to sign the transaction locally:

const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
signPromise
 .then((signedTx) => {
  web3.eth.sendSignedTransaction(
   signedTx.rawTransaction,
   function (err, hash) {
    if (!err) {
     console.log("Transaction hash:", hash);
    } else {
     console.log("Error submitting transaction:", err);
    }
   }
  );
 })
 .catch((err) => {
  console.log("Signing failed:", err);
 });

Upon success, you'll receive a transaction hash—proof your mint request was sent to the network.


Executing the Mint Function

Pass the IPFS URI of your uploaded metadata to the mintNFT function:

mintNFT("ipfs://QmZ643xL21yDh2BzBNHHuVqpXmYnDDfy69Asn3QSJxcbcu");

Then run:

node scripts/mint-nft.js

You should see output like:

Transaction hash: 0x0b0ab9a67c884c513dbd6f7e786e1a59a0d79f26606aaff0678c5367d5fd4b15

Check the status on Goerli Etherscan using this hash.

👉 Explore real-time blockchain analytics to track your NFT transactions instantly.


Viewing Your NFT in MetaMask

Once mined, view your NFT in the MetaMask mobile app:

  1. Switch MetaMask to the Goerli test network.
  2. Tap “Import Tokens” under Assets.
  3. Enter your contract address and Token ID (visible on Etherscan).
  4. Confirm import.

After a short delay, your NFT will appear—complete with image and metadata.

This step confirms successful minting and proper metadata resolution.


Frequently Asked Questions (FAQ)

Q: What is an NFT's tokenURI?
A: The tokenURI is a link to a JSON file describing the NFT’s metadata—its name, image, and attributes. It must resolve reliably; IPFS is ideal for decentralized hosting.

Q: Why use Goerli testnet instead of mainnet?
A: Goerli allows developers to test contracts and mint NFTs without spending real ETH. It mirrors Ethereum’s behavior safely and freely.

Q: Can I change NFT metadata after minting?
A: No—if metadata is stored immutably on IPFS. However, if hosted on updatable services (not recommended), changes are possible but compromise decentralization.

Q: How does signing work without exposing my private key?
A: Signing occurs locally in your script. The private key never leaves your machine—only the signed transaction is broadcast.

Q: What happens if I reuse the same tokenURI?
A: You’ll create multiple NFTs with identical properties but different IDs. True uniqueness comes from unique metadata per token.

Q: Is Alchemy required for minting NFTs?
A: No, but Alchemy simplifies node access with robust APIs, monitoring, and developer tools compared to running your own Ethereum node.


Final Thoughts

Minting an Ethereum NFT involves combining smart contracts, decentralized storage, and wallet integration into a seamless workflow. By mastering tools like Web3.js, IPFS, and Hardhat, you gain full control over digital asset creation in Web3.

Whether building a collection or experimenting with decentralized identity, this foundation prepares you for deeper exploration.

👉 Start building your own NFT projects with powerful crypto infrastructure today.