📜 ERC721 Standard: Non-Fungible Token Specification

Understand tokenId, ownerOf, and the functions that make NFTs unique

📜 ERC721 Standard

ERC721 is the Ethereum standard for NFTs. It defines the rules and functions that all NFT contracts must implement.

ERC721 vs ERC20

FeatureERC20 (Tokens)ERC721 (NFTs)
UniquenessAll tokens identicalEach token unique (ID)
DivisibilityCan send 0.5 tokensMust transfer whole NFT
TrackingBalance per addressOwner per token ID
Use CaseCurrency, governanceArt, collectibles, gaming

🔧 Interactive: ERC721 Functions

Click each function to explore how NFT contracts work:

mint()

function mint(address to, uint256 tokenId)

WriteGas: ~100,000

Creates a new NFT and assigns it to an address

Example Call:
mint(0x123...abc, 42)
Result:

Token #42 created and owned by 0x123...abc

Access: Usually restricted to contract owner/minter role

Required ERC721 Interface

interface IERC721 {
  // Transfer ownership of an NFT
  function transferFrom(address from, address to, uint256 tokenId) external;
  
  // Approve address to transfer specific NFT
  function approve(address to, uint256 tokenId) external;
  
  // Get owner of NFT
  function ownerOf(uint256 tokenId) external view returns (address);
  
  // Get balance (count of NFTs owned)
  function balanceOf(address owner) external view returns (uint256);
  
  // Get approved address for NFT
  function getApproved(uint256 tokenId) external view returns (address);
  
  // Events emitted on actions
  event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
  event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
}
⚠️

Important Differences

  • No decimals: ERC721 doesn't have decimals (can't send 0.5 NFTs)
  • Token ID required: Every function needs the specific NFT ID
  • Metadata: ERC721 adds tokenURI() to link to off-chain data