Ordinals Swap

circle-info

This contract is a part of the ordyswaparrow-up-right project repo.

Contract Summary

OrdinalSwap enables trustless peer-to-peer atomic swaps between Bitcoin Ordinals and STX tokens. This contract demonstrates cross-chain verification by validating Bitcoin transactions directly within Clarity, creating a bridge between Bitcoin and Stacks blockchains.

What this contract does:

  • Enables users to create STX offers for specific Ordinals (identified by txid and output index)

  • Escrows STX in the contract until the swap is completed or cancelled

  • Verifies Bitcoin transaction inclusion using Clarity Bitcoin library

  • Validates that the correct Ordinal was sent to the correct Bitcoin address

  • Releases escrowed STX to the seller upon proof of Ordinal transfer

  • Implements cancellation with a 50-block safety window to prevent front-running

  • Supports refunds after cancellation period expires

  • Targets "Genesis" Ordinals (first transfer from coinbase)

What developers can learn:

  • Cross-chain atomic swap patterns using hash-time-locked contracts

  • Bitcoin SPV (Simplified Payment Verification) on Stacks using clarity-bitcoin

  • Parsing and validating Bitcoin transactions within Clarity

  • Anti-front-running mechanisms with time-delayed cancellations

  • Escrow patterns for trustless exchanges

  • Working with Bitcoin transaction structures (inputs, outputs, txid)

  • Using block heights for time-based logic and safety windows

  • State management across multiple maps for complex workflows

  • Integration with external Clarity libraries (clarity-bitcoin)

Was this helpful?