How to Mint an NFT: A Step-by-Step Guide for Beginners

·

Minting non-fungible tokens (NFTs) has become one of the most exciting ways to enter the world of blockchain and digital ownership. From digital art selling for millions to unique collectibles, NFTs are transforming how creators monetize their work. In this comprehensive guide, you’ll learn how to mint your own NFT on the Ethereum blockchain using Alchemy, Solidity, and Web3 — all in under 10 minutes.

Whether you're a developer or a curious beginner, this tutorial walks you through each step with clear instructions and code examples. By the end, you’ll be equipped to mint your own NFTs anytime, anywhere.


Why Mint an NFT?

Before diving into the technical process, it’s important to understand what “minting” means in the context of NFTs. Minting an NFT refers to the act of publishing a unique token on a blockchain, typically representing digital art, music, or other forms of creative content. Once minted, the NFT becomes verifiably scarce and immutable.

High-profile creators like Beeple, 3LAU, and Grimes have leveraged blockchain technology — often powered by Alchemy's robust API infrastructure — to sell their digital works for millions. Now, with accessible tools and open-source frameworks, anyone can do the same.

👉 Discover how top creators launch their NFTs using powerful blockchain tools.


Prerequisites

To follow this tutorial, you should already have:

If you haven’t deployed your NFT smart contract yet, head back to Part 1 before proceeding.


Step 1: Install Web3

We’ll use Alchemy Web3, an enhanced version of the standard Web3 library that includes automatic retries and improved WebSocket support. It integrates seamlessly with Alchemy’s API.

Run the following command in your project directory:

npm install @alch/alchemy-web3

This package will allow us to interact with the Ethereum network programmatically and send transactions securely.


Step 2: Create the mint-nft.js File

Inside your scripts folder, create a new file called mint-nft.js. Begin by importing dependencies and initializing your Alchemy Web3 connection:

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

Make sure your .env file contains your Alchemy API key:

API_URL="https://eth-sepolia.g.alchemy.com/v2/your-api-key"

Step 3: Load Your Contract ABI

The Application Binary Interface (ABI) defines how we interact with our deployed smart contract. When you compiled your contract using Hardhat, it automatically generated a JSON file containing the ABI.

Add this line to load your contract’s ABI:

const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json");

To inspect the ABI structure during development, log it to the console:

console.log(JSON.stringify(contract.abi));

You can test this by running:

node scripts/mint-nft.js

Step 4: Store Metadata on IPFS Using Pinata

An NFT is only as valuable as its metadata — which includes name, description, image, and attributes. To ensure decentralization, we store this data on IPFS (InterPlanetary File System).

We’ll use Pinata, a user-friendly IPFS gateway, to pin our files permanently.

Upload Your NFT Image

  1. Go to Pinata.cloud and sign up (free tier available).
  2. Click “Upload” and select your image file.
  3. After uploading, copy the CID (Content Identifier).
  4. Access your image via: https://gateway.pinata.cloud/ipfs/<your-image-cid>

Create and Upload Metadata JSON

Create a file named nft-metadata.json in your root directory:

{
  "name": "Ramses",
  "description": "The world's most adorable and sensitive pup.",
  "image": "ipfs://QmWmvTJmJU3pozR9ZHFmQC2DNDwi2XJtf3QGyYiiagFSWb",
  "attributes": [
    { "trait_type": "Breed", "value": "Maltipoo" },
    { "trait_type": "Eye color", "value": "Mocha" }
  ]
}

Replace the image URL with your own IPFS link. Then upload this JSON file to Pinata just like the image.

Keep the metadata CID — you’ll need it as the tokenURI.


Step 5: Create Your Contract Instance

Now that we have the ABI and contract address (from deployment), we can create a JavaScript instance of our contract.

Find your contract address from Etherscan or your deployment logs. Example:

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

This instance allows us to call functions like mintNFT() directly from code.


Step 6: Update Your .env File

Ensure your .env file includes both public and private keys:

API_URL="https://eth-sepolia.g.alchemy.com/v2/your-api-key"
PRIVATE_KEY="your-private-account-address"
PUBLIC_KEY="your-public-account-address"

We'll use these to sign transactions securely without exposing sensitive data.


Step 7: Build the Transaction

Let’s define the mintNFT function. This will:

Here’s the full implementation:

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(),
  };
}

Note: The mintNFT function in your Solidity contract must accept two parameters: _to (recipient) and _tokenURI.


Step 8: Sign and Send the Transaction

Now sign the transaction using your private key:

const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
signPromise
  .then((signedTx) => {
    web3.eth.sendSignedTransaction(
      signedTx.rawTransaction,
      function (err, hash) {
        if (!err) {
          console.log("The hash of your transaction is:", hash);
          console.log("Check Alchemy's Mempool to view its status!");
        } else {
          console.log("Something went wrong:", err);
        }
      }
    );
  })
  .catch((err) => {
    console.log("Promise failed:", err);
  });

This ensures your transaction is cryptographically secure and broadcasted to the network.


Step 9: Run the Script

Finally, call the function with your metadata URI:

mintNFT("ipfs://QmYueiuRNmL4MiA2GwtVMm6ZagknXnSpQnB3z2gWbz36hP");

Run it:

node scripts/mint-nft.js

You should see output like:

The hash of your transaction is: 0x301791fdf492001fcd9d5e5b12f3aa1bbbea9a88ed24993a8ab2cdae2d06e1e8
Check Alchemy's Mempool to view the status of your transaction!

Track your transaction on Sepolia Etherscan using the hash.

👉 See real-time NFT transactions powered by high-performance blockchain APIs.


Frequently Asked Questions (FAQ)

What does it mean to mint an NFT?

Minting an NFT means publishing a unique digital token on a blockchain. It turns digital files into verifiable assets with proof of ownership and scarcity.

Is minting an NFT free?

No — minting requires paying gas fees on the Ethereum network. However, using testnets like Sepolia allows you to practice without spending real money.

Can I mint multiple NFTs from one contract?

Yes! Once your ERC-721 contract is deployed, you can call mintNFT() repeatedly with different tokenURIs to create unlimited unique tokens.

Where should I store my NFT metadata?

Always use decentralized storage like IPFS or Arweave. Storing metadata on centralized servers risks loss or manipulation over time.

How do I verify my NFT after minting?

Use Etherscan or Alchemy’s tools to check the transaction status. You can also view your NFT in wallets like MetaMask once added manually.

What is a nonce in Ethereum transactions?

A nonce is a number that tracks how many transactions have been sent from an address. It prevents replay attacks and ensures transaction order.


Final Thoughts

Congratulations! You’ve successfully minted your first NFT using Alchemy, Solidity, and Web3. This foundational skill opens doors to building marketplaces, launching digital collections, or even creating generative art projects.

With tools becoming more accessible than ever, now is the perfect time to explore the creative potential of blockchain technology.

👉 Start building your next NFT project with enterprise-grade infrastructure.