Example Contracts

How Clarity contracts look in practice

This page collects example Clarity contracts that developers can use as practical starting points when building on Stacks.

You’ll find starter contracts that demonstrate common patterns and best practices in Clarity, as well as notable production contracts currently used by popular Stacks applications. Together, these examples are intended to help you understand how real-world contracts are structured, how different features are implemented, and how Clarity is used in practice.

Use these contracts as references, learning aids, or foundations to adapt and extend for your own applications.

Tokens

Example Templates

Real Implementations


DeFi

Example Templates

  • DeFi Lending: A DeFi lending protocol that allows users to deposit STX, borrow against their deposits, and earn yield from interest payments.

  • NFT Marketplace: A tiny NFT marketplace contract that enables users to list, buy, and sell NFTs with flexible payment options.

  • AMM DEXarrow-up-right: A minimal, production-ready decentralized exchange (DEX) on Stacks (Bitcoin L2) implementing a constant-product AMM (x · y = k).

Real Implementations


Utilities

Example Templates

  • Smart Wallets: A smart contract wallet with specific rules, which is a sophisticated wallet abstraction that enables programmable spending rules and multi-admin governance.

  • Send Many: Enables efficient batch STX transfers to multiple recipients in a single transaction.

  • Counter: A simple on-chain counter that maintains individual count values for each principal address.

  • Multi-Sig Vaultarrow-up-right: A simple multisig vault that allows members to vote on who should receive the STX contents.

  • Timelocked Walletarrow-up-right: A time-locked vault contract that becomes eligible to claim by the beneficiary after a certain block-height has been reached.

Real Implementations


Cross-chain

  • Ordinals Swap: Enables trustless peer-to-peer atomic swaps between Bitcoin Ordinals and STX tokens.

  • Clarity Bitcoin Libraryarrow-up-right: A stateless contract that enables you to verify that a transaction was mined in a certain Bitcoin block and parse a bitcoin transaction.


DAOs

Example Templates


Other notable contracts on mainnet

  • Proof of Transfer (PoX): The core system contract that implements Stacks' consensus mechanism, enabling STX holders to lock their tokens and earn Bitcoin rewards.

  • SIP-019 Token Metadata Updatearrow-up-right: A helper contract that emits a SIP-019 print event notification for updating token metadata.

  • BNS v2arrow-up-right: A decentralized naming system built on the Stacks blockchain. It allows users to register, manage, and transfer names within different namespaces.

Last updated

Was this helpful?