Creating your own NFT on the Ethereum blockchain has never been more accessible. Whether you're a developer exploring Web3 or an artist looking to tokenize digital creations, this step-by-step guide will walk you through deploying your very own ERC-721 smart contract on the Sepolia test network using industry-standard tools like Hardhat, Solidity, Metamask, and Alchemy.
By the end of this tutorial, you’ll have a fully deployed NFT smart contract—no prior blockchain experience required.
What Is an NFT?
A Non-Fungible Token (NFT) is a unique digital asset verified using blockchain technology. Unlike cryptocurrencies such as ETH, which are interchangeable, each NFT has distinct properties and cannot be exchanged on a one-to-one basis. Most NFTs on Ethereum follow the ERC-721 token standard, which defines how ownership, transfer, and metadata are managed.
This guide focuses on creating an ERC-721 compliant smart contract that allows you to mint your own NFTs in future steps.
Prerequisites
Before diving in, ensure your development environment is ready:
- Install Node.js (version >14) and npm
- Basic understanding of command-line interfaces
- Code editor (e.g., VS Code)
You can verify your Node.js installation by running:
node --versionStep 1: Create an Alchemy App
Alchemy powers millions of dApps with reliable blockchain APIs. We’ll use it to deploy and monitor our smart contract.
- Go to the Alchemy Dashboard and sign up.
- Hover over Apps → Click Create App
Fill in:
- Name:
MyNFT - Description: "My first NFT project"
- Chain: Ethereum
- Network: Sepolia
- Name:
- Click Create App
Once created, click View Key and copy your HTTP API key. You'll need it later.
👉 Start building with powerful blockchain tools today.
Step 2: Set Up Metamask Wallet
Metamask is a browser-based wallet for managing Ethereum accounts and signing transactions.
- Download Metamask at metamask.io
- Create a new wallet
- Switch network to Sepolia Test Network (top-right corner)
Keep your seed phrase secure—never share it!
Step 3: Get Sepolia ETH from a Faucet
To deploy contracts on the testnet, you need gas in the form of Sepolia ETH.
Visit Alchemy’s Sepolia Faucet, connect your Metamask wallet, and request funds. Depending on network traffic, you may need to authenticate via Alchemy.
Wait a few moments, then check your Metamask balance—it should reflect the received test ETH.
Step 4: Initialize Your Node Project
Open your terminal and run:
mkdir my-nft-project
cd my-nft-project
npm init -yThis sets up a fresh Node.js project.
Step 5: Install Hardhat
Hardhat is the go-to development environment for Ethereum smart contracts.
In your project folder, run:
npm install --save-dev hardhatThen initialize Hardhat:
npx hardhatSelect Create a JavaScript project, accept default settings (including adding .gitignore and installing dependencies).
Test the setup:
npx hardhat testIf tests pass, you’re good to go.
Step 6: Install Required Dependencies
We’ll need additional packages for security and functionality:
npm install dotenv
npm uninstall ethers
npm install ethers@5 @nomicfoundation/hardhat-toolboxThese include:
dotenv– for managing sensitive keysethers@5– compatible with Hardhat for contract interaction@nomicfoundation/hardhat-toolbox– essential plugins bundle
Step 7: Write the NFT Smart Contract
Navigate to the contracts/ folder and create MyNFT.sol.
Paste the following Solidity 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;
}
}Understanding the Code
- Inheritance: Uses OpenZeppelin’s
ERC721URIStoragefor standard NFT functionality andOwnablefor access control. - Constructor: Sets NFT name (
MyNFT) and symbol (NFT) - mintNFT(): Allows owner-only minting with a
tokenURIpointing to metadata (like image, name, etc.)
Ensure Solidity version matches in hardhat.config.js.
Step 8: Configure Environment Variables
Create a .env file in the root directory:
ALCHEMY_API_KEY="your-api-key-here"
PRIVATE_KEY="your-metamask-private-key"👉 Securely manage your blockchain workflows with advanced developer tools.
To export your private key from Metamask:
- Open Metamask → Account Options → Export Private Key
- Enter password and copy key (keep it secret!)
Add .env to .gitignore to prevent accidental exposure.
Step 9: Update Hardhat Configuration
Replace hardhat.config.js contents:
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: [process.env.PRIVATE_KEY],
},
},
};This configures Hardhat to deploy on Sepolia using Alchemy and your wallet.
Step 10: Create 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("MyNFT deployed to:", myNFT.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});This script compiles and deploys your contract.
Step 11: Deploy the Contract
Run the deployment command:
npx hardhat run scripts/deploy.js --network sepoliaOn success, you’ll see output like:
MyNFT deployed to: 0x...Copy the contract address.
Verify Deployment on Etherscan
Go to Sepolia Etherscan and search your contract address.
You should see:
- Transaction labeled Contract Creation
- From address matching your Metamask wallet
- Successful deployment status
Click into the transaction to confirm details.
🎉 Congratulations! You’ve deployed an NFT smart contract on Ethereum’s testnet.
Core Keywords
Throughout this guide, we’ve naturally integrated key SEO terms:
- Create an NFT
- Ethereum NFT tutorial
- ERC-721 smart contract
- Deploy NFT on Sepolia
- Alchemy API
- Hardhat tutorial
- Solidity contract
- Metamask wallet
These align with common search queries while maintaining readability.
Frequently Asked Questions (FAQ)
How much does it cost to create an NFT?
On the Sepolia testnet, deployment uses test ETH—completely free. On mainnet, gas fees vary based on network congestion but typically range from $10–$50 for simple contracts.
Can anyone mint my NFT after deployment?
No—this contract uses onlyOwner, restricting minting to the deployer. Anyone can mint if you remove this modifier and adjust permissions accordingly.
What is tokenURI in an NFT?
The tokenURI is a link to a JSON file containing metadata: name, description, image URL, attributes. It's often hosted on IPFS via services like Pinata.
Why use Hardhat instead of Truffle?
Hardhat offers better debugging, built-in console.log support, and seamless integration with tools like Ethers.js and Alchemy—making it ideal for modern dApp development.
Is my private key safe when stored in .env?
Yes—as long as you never commit .env to public repositories. Always add it to .gitignore. Never share or expose your private key.
What’s next after deploying the contract?
Next steps include minting your first NFT programmatically and viewing it in your wallet. We’ll cover these in upcoming guides.
👉 Continue your Web3 journey with trusted infrastructure and tools.
With your smart contract live, you're now ready to begin minting unique digital assets. Stay tuned for Part II: How to Mint an NFT from Code, where we’ll call the mintNFT() function and bring your creation to life.