Creating your first NFT on the Ethereum blockchain may seem intimidating, but with the right tools and guidance, it's a straightforward process. This comprehensive tutorial walks you through every step—from setting up your development environment to deploying your ERC-721 smart contract on the Sepolia test network. Whether you're new to blockchain or building your first decentralized application (dApp), this guide ensures you’ll publish your very own NFT with confidence.
By the end of this guide, you'll have deployed a fully functional NFT smart contract using industry-standard tools like Hardhat, Solidity, and Alchemy, all without spending real ETH.
Prerequisites
Before diving in, ensure your machine meets these basic requirements:
- Node.js (version 14 or higher)
- npm (Node Package Manager)
You can verify your installation by running the following command in your terminal:
node -vOnce confirmed, proceed to the next steps.
Step 1: Create an Alchemy App
Alchemy is a powerful blockchain development platform that simplifies interaction with the Ethereum network. To get started:
- Visit the Alchemy dashboard and sign up if you haven’t already.
- Hover over the Apps dropdown and click Create App.
Fill in:
- Name: e.g., “MyNFTProject”
- Description: A brief note about your project
- Chain: Ethereum
- Network: Sepolia
- Click Create App.
After creation, click View Key and securely save your HTTP API key—you’ll use it later to connect your local project to Alchemy’s infrastructure.
👉 Get started with Alchemy today and power your Ethereum development.
Step 2: Set Up a Metamask Wallet
To interact with Ethereum, you need a digital wallet. We recommend MetaMask, a browser extension that manages your accounts and private keys securely.
- Download MetaMask for free at metamask.io.
- Create a new wallet and securely back up your seed phrase.
- Switch your network to Sepolia Test Network from the top dropdown menu.
This ensures you’re using test ETH instead of real funds during development.
Step 3: Get Test ETH from a Faucet
Deploying contracts requires gas fees—even on testnets. Fortunately, you can obtain free SepoliaETH via faucets.
Use Alchemy’s official Sepolia Faucet to request test tokens:
- Enter your MetaMask wallet address.
- Complete any required authentication (e.g., signing in with Alchemy).
- Wait a few moments for the transaction to confirm.
Refresh your MetaMask balance—you should now see SepoliaETH ready for use.
Step 4: Initialize Your Node Project
Open your terminal and run:
mkdir my-nft-project
cd my-nft-project
npm init -yThis creates a new directory and initializes a Node.js project with default settings.
Step 5: Install Hardhat
Hardhat is the go-to Ethereum development environment for compiling, testing, and deploying smart contracts.
Run the following commands:
npm install --save-dev hardhat
npx hardhatSelect Create a JavaScript project, then accept all default options (including adding .gitignore and installing sample dependencies).
Test your setup:
npx hardhat compileIf you see “Nothing to compile,” that’s expected—we haven’t added any contracts yet!
Now install OpenZeppelin Contracts, which provides secure, community-audited implementations of ERC standards:
npm install @openzeppelin/contractsStep 6: Install dotenv for Environment Management
Keep sensitive data like API keys and private keys secure by using environment variables.
Install dotenv:
npm install dotenvStep 7: Uninstall Conflicting Ethers Version
To prevent version conflicts, remove any existing ethers library:
npm uninstall ethersStep 8: Install Ethers.js v5 and Hardhat Ethers Plugin
Install compatible versions:
npm install --save-dev @nomicfoundation/hardhat-toolboxThis package includes ethers, hardhat-ethers, and other essential plugins.
Step 9: Write Your NFT Smart Contract
Using Solidity, Ethereum’s primary smart contract language, create your NFT contract.
- In your project root, navigate to or create a
contracts/folder. - Create a file named
MyNFT.sol.
Paste the following code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyNFT is ERC721URIStorage, Ownable {
uint256 public tokenCounter;
constructor() ERC721("MyNFT", "NFT") Ownable(msg.sender) {
tokenCounter = 0;
}
function mintNFT(address recipient, string memory tokenURI) public onlyOwner returns (uint256) {
uint256 newTokenId = tokenCounter;
_safeMint(recipient, newTokenId);
_setTokenURI(newTokenId, tokenURI);
tokenCounter++;
return newTokenId;
}
}Code Breakdown
- Line 5–6: Import OpenZeppelin’s
ERC721URIStorage(standard NFT functionality with metadata support) andOwnable(access control). - Constructor: Sets your contract name (“MyNFT”) and symbol (“NFT”). Customize these as desired.
mintNFT()Function: Allows only the owner to mint new tokens. It takes:recipient: The wallet address receiving the NFT.tokenURI: A link to JSON metadata (e.g., hosted on IPFS via Pinata).
🔍 Want to allow public minting? RemoveonlyOwnerfrom the function andOwnableinheritance.
Step 10: Connect MetaMask & Alchemy via Environment Variables
Never hardcode private keys or API secrets. Instead, use a .env file:
- Create
.envin your project root. - Add:
ALCHEMY_API_KEY="your-alchemy-http-key"
PRIVATE_KEY="your-metamask-private-key"Replace values with actual keys from Alchemy and your MetaMask export.
👉 Securely manage your blockchain credentials with best practices.
Step 11: Configure Hardhat
Update hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.20",
networks: {
sepolia: {
url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
accounts: [`0x${process.env.PRIVATE_KEY}`],
},
},
};This configures Hardhat to deploy using Alchemy’s Sepolia endpoint and your MetaMask account.
Step 12: Write the Deployment Script
Create a scripts/deploy.js file:
const { ethers } = require("hardhat");
async function main() {
const MyNFT = await ethers.getContractFactory("MyNFT");
const myNFT = await MyNFT.deploy();
await myNFT.deployed();
console.log("Contract deployed to:", myNFT.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});This script compiles and deploys your contract to Sepolia.
Step 13: Deploy Your NFT Contract
Run the deployment:
npx hardhat run scripts/deploy.js --network sepoliaOn success, you’ll see output like:
Contract deployed to: 0x...Verify deployment by searching the contract address on Sepolia Etherscan. The transaction should show “Contract Creation” under the To field.
🎉 Congratulations! You’ve successfully published an NFT smart contract on Ethereum.
What Happens Behind the Scenes?
When you deploy, Hardhat uses JSON-RPC calls like:
eth_sendRawTransaction: Submits your signed contract creation.eth_getTransactionByHash: Fetches transaction details after submission.
These are logged automatically in your Alchemy dashboard—check them out to observe real-time blockchain interactions.
Frequently Asked Questions (FAQ)
Q: What is an NFT?
An NFT (Non-Fungible Token) is a unique digital asset stored on a blockchain. Unlike cryptocurrencies, each NFT has distinct value and properties, often representing art, collectibles, or digital ownership rights.
Q: Why use the Sepolia testnet?
Sepolia allows developers to test smart contracts without risking real funds. It mirrors Ethereum’s mainnet behavior while using free test ETH.
Q: Can I mint multiple NFTs with one contract?
Yes! Your deployed contract can mint unlimited NFTs via repeated calls to mintNFT(). Each gets a unique ID starting from 0.
Q: Where should I store NFT metadata?
Use decentralized storage like IPFS (via Pinata) or Arweave. Upload images and JSON files there, then pass the resulting URL as tokenURI.
Q: Is this ERC-721 compliant?
Absolutely. By inheriting OpenZeppelin’s ERC721URIStorage, your contract follows the full ERC-721 standard, ensuring compatibility across wallets and marketplaces.
Q: How do I view my NFT in MetaMask?
After minting, add the NFT manually by contract address and token ID in MetaMask. In Part II of this series, we’ll cover minting and automatic detection.
Ready to mint your first token? Stay tuned for Part II: How to Mint an NFT From Code.
Until then, explore more blockchain tools and supercharge your Web3 journey.