NFTs & Token Standards

Understanding Non-Fungible Tokens and Token Standards

What are NFTs?

Non-Fungible Tokens (NFTs) are unique digital assets that represent ownership of a specific item or piece of content. Unlike cryptocurrencies like Bitcoin or Ethereum, which are fungible (interchangeable), each NFT is unique and cannot be replaced by another token.

Key Characteristics of NFTs

🔒 Uniqueness

Each NFT has a unique identifier and cannot be duplicated or replaced by another token.

🏷️ Indivisibility

NFTs cannot be divided into smaller units like cryptocurrencies. You own the entire token or none of it.

📜 Verifiable Ownership

Ownership is recorded on the blockchain and can be verified by anyone, providing proof of authenticity.

🔄 Transferable

NFTs can be bought, sold, and traded on various marketplaces, with ownership transfers recorded on-chain.

ERC-721: The NFT Standard

ERC-721 is the most widely used standard for NFTs on Ethereum. It defines the basic functionality that all NFTs must implement:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyNFT is ERC721, Ownable {
    uint256 private _tokenIdCounter;
    
    constructor() ERC721("MyNFT", "MNFT") {}
    
    function mint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter;
        _tokenIdCounter++;
        _safeMint(to, tokenId);
    }
    
    function _baseURI() internal pure override returns (string memory) {
        return "https://api.mynft.com/metadata/";
    }
}

ERC-1155: Multi-Token Standard

ERC-1155 is a more advanced standard that allows for both fungible and non-fungible tokens in a single contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MultiToken is ERC1155, Ownable {
    constructor() ERC1155("https://api.multitoken.com/metadata/{id}.json") {}
    
    function mint(
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public onlyOwner {
        _mint(to, id, amount, data);
    }
    
    function mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public onlyOwner {
        _mintBatch(to, ids, amounts, data);
    }
}

NFT Metadata Standards

NFTs typically store metadata off-chain and reference it via a URI. The most common standard is the ERC-721 metadata extension:

Metadata Structure:

{
  "name": "My Awesome NFT",
  "description": "This is a description of my NFT",
  "image": "https://example.com/image.png",
  "attributes": [
    {
      "trait_type": "Color",
      "value": "Blue"
    },
    {
      "trait_type": "Rarity",
      "value": "Legendary"
    }
  ]
}

Popular NFT Use Cases

🎨 Digital Art

Artists can create, sell, and trade digital artwork as NFTs, with royalties built into smart contracts for ongoing revenue.

🎮 Gaming

In-game items, characters, and assets can be tokenized as NFTs, allowing players to own and trade their virtual possessions.

🏠 Real Estate

Property ownership can be represented as NFTs, enabling fractional ownership and easier transfer of real estate assets.

🎫 Tickets & Events

Event tickets can be issued as NFTs, preventing counterfeiting and enabling programmable features like resale restrictions.

NFT Marketplaces

Several marketplaces facilitate NFT trading:

OpenSea

The largest NFT marketplace supporting multiple blockchains and token standards.

  • • Supports ERC-721 and ERC-1155
  • • No coding required to list NFTs
  • • Built-in royalty system
  • • Multiple payment options

Foundation

Curated marketplace focused on high-quality digital art and creative works.

  • • Invitation-only for creators
  • • Focus on digital art
  • • Higher quality standards
  • • Community-driven curation

Building NFT Applications

Here's how to interact with NFTs using Web3 libraries:

// Interacting with NFTs using Ethers.js
import { ethers } from 'ethers';

const nftABI = [
  "function ownerOf(uint256 tokenId) view returns (address)",
  "function tokenURI(uint256 tokenId) view returns (string)",
  "function transferFrom(address from, address to, uint256 tokenId) external",
  "function approve(address to, uint256 tokenId) external"
];

const nftAddress = '0x...';
const contract = new ethers.Contract(nftAddress, nftABI, provider);

// Get NFT owner
const owner = await contract.ownerOf(1);
console.log('Owner of token 1:', owner);

// Get NFT metadata URI
const tokenURI = await contract.tokenURI(1);
console.log('Token URI:', tokenURI);

// Transfer NFT
const tx = await contract.transferFrom(
  fromAddress,
  toAddress,
  tokenId
);
await tx.wait();

// Approve NFT for marketplace
const approveTx = await contract.approve(marketplaceAddress, tokenId);
await approveTx.wait();

NFT Development Best Practices

Development Guidelines:

  • Use Established Standards: Stick to ERC-721 or ERC-1155 for compatibility
  • Optimize Metadata: Use IPFS or similar for decentralized metadata storage
  • Implement Royalties: Consider EIP-2981 for standardized royalty payments
  • Gas Optimization: Batch operations when possible to reduce costs
  • Security: Implement proper access controls and validation
  • User Experience: Make minting and trading processes intuitive
  • Metadata Standards: Follow established metadata formats for marketplace compatibility

Future of NFTs

The NFT ecosystem continues to evolve with new standards and use cases:

Emerging Trends:

  • Dynamic NFTs: NFTs that change based on external data or conditions
  • Utility NFTs: NFTs that provide access to services or experiences
  • Fractional Ownership: Splitting expensive NFTs into smaller, tradeable shares
  • Cross-Chain NFTs: NFTs that can move between different blockchains
  • AI-Generated Content: NFTs created by artificial intelligence
  • Environmental NFTs: NFTs tied to real-world environmental projects

Summary

In this final chapter, we've explored NFTs and token standards:

  • • NFTs are unique, indivisible digital assets representing ownership
  • • ERC-721 is the standard for individual NFTs
  • • ERC-1155 allows for both fungible and non-fungible tokens
  • • Metadata standards ensure compatibility across marketplaces
  • • NFTs have diverse use cases from art to gaming to real estate
  • • The NFT ecosystem continues to evolve with new standards and applications

Congratulations! You've completed the Ethereum development curriculum. You now have a solid foundation in Ethereum development, from smart contracts to DeFi protocols to NFTs. Continue building and exploring the vast possibilities of blockchain technology!