NFT Marketplace

Contract Summary

A tiny NFT marketplace contract that enables users to list, buy, and sell NFTs with flexible payment options. This contract demonstrates trait-based programming and comprehensive marketplace mechanics including expiry, whitelisting, and optional buyer targeting.

What this contract does:

  • Allows NFT owners to list their tokens for sale with customizable terms

  • Supports both STX and SIP-010 fungible token payments

  • Implements listing expiry based on block height

  • Enables optional buyer restriction (private sales to specific principals)

  • Requires contract whitelisting for both NFT and payment assets

  • Escrows NFTs in the marketplace contract until sale or cancellation

  • Allows sellers to cancel active listings and reclaim their NFTs

  • Validates all listing parameters before accepting offers

  • Assigns unique IDs to each listing for tracking

What developers can learn:

  • Using Clarity traits (<nft-trait> and <ft-trait>) for generic contract interactions

  • Implementing marketplace escrow patterns with NFT custody

  • Contract whitelisting pattern for security and quality control

  • Time-based expiry using block heights

  • Optional parameters with (optional principal) for flexible configurations

  • Comprehensive input validation and error handling

  • Using contract-of to verify trait implementations

  • Pattern matching with match for optional values

  • Private helper functions for validation and transfers

  • Nonce-based unique ID generation with data variables

  • As-contract context switching for escrowed asset transfers

Was this helpful?