By Nico
If you're a developer exploring blockchain technology, NFTs (Non-Fungible Tokens) are an exciting entry point. This tutorial will walk you through creating your own NFT with just 14 lines of Solidity code—no prior Ethereum or smart contract experience required.
By the end, you'll have:
✅ A functional Ethereum wallet
✅ Your own minted NFT
✅ Hands-on experience with ERC-721 standards
Understanding NFTs: The Basics
What Exactly Are NFTs?
NFTs represent unique digital ownership on the blockchain. Unlike cryptocurrencies (which are interchangeable), each NFT is one-of-a-kind. They're commonly used for:
- Digital art
- Collectibles
- Virtual real estate
Key characteristics:
🔒 Immutable ownership records
🖼️ Tamper-proof metadata
👥 Single verified owner at any time
The ERC-721 Standard Explained
ERC-721 is the technical standard for NFTs on Ethereum. It requires smart contracts to implement specific methods like:
ownerOf()– Identifies token ownershiptransferFrom()– Handles transferstokenURI()– Links to metadata
Open-source libraries like OpenZeppelin simplify development by providing pre-built ERC-721 templates.
NFT Minting: How It Works
Minting publishes your unique token on the blockchain. Each NFT contains:
- A tokenURI pointing to metadata
A JSON file with attributes like:
{ "name": "Digital Art #1", "description": "Unique blockchain artwork", "image": "ipfs://QmXx...", "attributes": [ {"trait_type": "Rarity", "value": "Legendary"} ] }
Storing NFT Metadata
Three primary methods:
| Method | Pros | Cons |
|---|---|---|
| On-chain | Fully decentralized | High gas fees |
| IPFS | Immutable content | Requires pinning service |
| Centralized API | Easy setup | Less secure |
For this tutorial, we'll use a simple API approach.
Building Your NFT: Step-by-Step
Prerequisites
MetaMask Wallet (Download here)
- Set to Ropsten Test Network
- Get test ETH from Ropsten Faucet
Alchemy Account (Sign up)
- Create an Ethereum app
- Note your HTTP API key
- Node.js & NPM (Install guide)
Project Setup
Initialize your project structure:
mkdir nft-project
cd nft-project
mkdir ethereum web1. Smart Contract Setup
cd ethereum
npm init -y
npm install --save-dev hardhat @nomiclabs/hardhat-ethers @openzeppelin/contracts
npx hardhat initCreate contracts/EmotionalShapes.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract EmotionalShapes is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("EmotionalShapes", "ESS") {}
function _baseURI() internal pure override returns (string memory) {
return "YOUR_API_URL/api/erc721/";
}
function mint(address to) public returns (uint256) {
require(_tokenIdCounter.current() < 3);
_tokenIdCounter.increment();
_safeMint(to, _tokenIdCounter.current());
return _tokenIdCounter.current();
}
}2. API Endpoint Setup
Create web/pages/api/erc721/[id].js:
const metadata = {
1: {
name: "Sad Circle",
description: "A sad geometric shape",
image: "https://i.imgur.com/Qkw9N0A.jpeg",
attributes: [
{ trait_type: "Mood", value: "Sad" }
]
}
};
export default function handler(req, res) {
res.status(200).json(metadata[req.query.id] || {});
}Deployment & Minting
1. Compile and Deploy
npx hardhat compile
node scripts/deploy.js👉 View your contract on Etherscan after deployment.
2. Mint Your NFT
Run the minting script:
node scripts/mint.jsCheck your MetaMask mobile app to view the NFT!
Frequently Asked Questions
How much does it cost to mint an NFT?
On Ethereum mainnet, fees vary (often $50-$300). Using testnets like Ropsten is free for development.
Can I sell my NFT after minting?
Yes! Marketplaces like OpenSea support ERC-721 tokens. Future tutorials will cover building a sales interface.
What's the difference between ERC-721 and ERC-1155?
ERC-1155 allows semi-fungible tokens (useful for game items), while ERC-721 is strictly for unique assets.
Next Steps
- Expand your NFT collection
- Build a React frontend to display NFTs
- 👉 Explore advanced NFT development
Ready to create your next NFT masterpiece? The blockchain canvas awaits your creativity! 🎨