NFT Standards

NFT Standards

Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features

Category: design Source: wshobson/agents

NFT Standards

Mastering NFT standards is essential for anyone developing digital asset systems, NFT collections, or marketplaces on Ethereum and compatible blockchains. This skill focuses on implementing the most widely adopted NFT standards-ERC-721 and ERC-1155-with best practices for metadata, minting strategies, marketplace integration, and advanced features such as royalties and dynamic NFTs.

What Is This?

The "NFT Standards" skill covers:

  • ERC-721: The original standard for non-fungible tokens, enabling unique digital assets.
  • ERC-1155: A multi-token standard supporting both fungible and non-fungible assets within a single contract.
  • Metadata Handling: Techniques for structuring and serving NFT metadata, both on-chain and off-chain.
  • Minting Strategies: Approaches for controlled, fair, and scalable NFT minting.
  • Marketplace Integration: Ensuring NFTs are compliant with major marketplaces through proper interface and metadata support.
  • Advanced Features: Implementation of royalties, soulbound (non-transferable) tokens, and dynamic/evolving NFTs.

These components are critical when creating NFT collections, building marketplaces, or developing any system that manages digital ownership or collectibles.

Why Use It?

NFTs (Non-Fungible Tokens) represent unique ownership of digital or physical items using blockchain technology. Adhering to established standards like ERC-721 and ERC-1155 ensures:

  • Interoperability: NFTs can be recognized and traded across different platforms and marketplaces.
  • Security: Well-audited standards reduce the risk of vulnerabilities.
  • Feature Richness: Standards support advanced use cases such as batch transfers, royalties, and metadata updates.
  • Ecosystem Compatibility: Major tools, wallets, and marketplaces rely on these standards for seamless integration.

By mastering NFT standards, developers can create robust, secure, and widely-compatible NFT contracts that are ready for both current and future applications.

How to Use It

ERC-721 Implementation

ERC-721 defines a minimal interface for non-fungible tokens. Here is a basic implementation using OpenZeppelin’s audited contracts:

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

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract MyNFT is ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    uint256 public constant MAX_SUPPLY = 10000;
    uint256 public constant MINT_PRICE = 0.08 ether;
    uint256 public constant MAX_PER_MINT = 20;

    constructor() ERC721("MyNFT", "MNFT") {}

    function mint(uint256 quantity) external payable {
        require(quantity > 0 && quantity <= MAX_PER_MINT, "Invalid quantity");
        require(_tokenIds.current() + quantity <= MAX_SUPPLY, "Exceeds supply");
        require(msg.value == MINT_PRICE * quantity, "Incorrect ETH sent");

        for (uint256 i = 0; i < quantity; i++) {
            _tokenIds.increment();
            uint256 newItemId = _tokenIds.current();
            _mint(msg.sender, newItemId);
            _setTokenURI(newItemId, string(abi.encodePacked("ipfs://...", uint2str(newItemId))));
        }
    }
}

This example shows batch minting, price enforcement, and on-chain linking to off-chain metadata.

ERC-1155 Implementation

ERC-1155 allows multiple token types (fungible, non-fungible, and semi-fungible) 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 MyMultiToken is ERC1155, Ownable {
    uint256 public constant GOLD = 1;
    uint256 public constant ART = 2;

    constructor() ERC1155("https://api.example.com/metadata/{id}.json") {}

    function mint(address to, uint256 id, uint256 amount) public onlyOwner {
        _mint(to, id, amount, "");
    }
}

This structure supports batch minting and transfer, significantly reducing gas costs for large-scale collections or gaming assets.

Metadata Best Practices

NFT metadata can be stored directly on-chain or referenced via a URI (e.g., IPFS, centralized servers). Metadata should follow the ERC-721 Metadata JSON Schema:

{
  "name": "My NFT #1",
  "description": "This is an example NFT.",
  "image": "ipfs://Qm.../image.png",
  "attributes": [
    { "trait_type": "Rarity", "value": "Legendary" }
  ]
}

Serving consistent and reliable metadata ensures optimal display on marketplaces and wallets.

Advanced Features

  • Royalties: Use EIP-2981 to specify royalty information for secondary sales.
  • Soulbound Tokens: Prevent transfers by overriding the _beforeTokenTransfer hook.
  • Dynamic NFTs: Allow metadata to update based on external events or conditions.

When to Use It

Apply NFT standards when:

  • Creating NFT collections (art, gaming, collectibles)
  • Building NFT marketplaces or integrating with existing ones
  • Designing on-chain or off-chain metadata systems
  • Creating non-transferable (soulbound) tokens
  • Implementing royalty and revenue sharing mechanisms
  • Developing dynamic or evolving NFTs that change over time

Important Notes

  • Standard Compliance: Always inherit from OpenZeppelin or similarly audited contracts to ensure security and compatibility.
  • Metadata Immutability: Prefer immutable metadata for art collectibles to avoid trust issues. For dynamic NFTs, clearly communicate update rules.
  • Gas Optimization: Use batch minting and efficient storage to minimize transaction costs, especially with ERC-1155.
  • Marketplace Integration: Test your contracts on major NFT marketplaces to ensure correct metadata rendering and feature support.
  • Security: Regularly audit contracts and follow best practices to avoid exploits related to minting, transfers, and metadata.

By mastering NFT standards, you can build scalable, secure, and interoperable NFT platforms that are ready for the rapidly evolving digital asset ecosystem.