Skip to main content
Add, test, and deploy Clarity contracts with auto-generated TypeScript bindings. New projects default to Clarity 6 (epoch 4.0).

Contents

Creating contracts

Use the CLI to add new contracts to your project:
Each command creates the .clar file, a Vitest test, updates Clarinet.toml with the correct epoch, adds trait requirements for SIP templates, and regenerates TypeScript bindings.

Sample contract

The default scaffolded counter contract demonstrates data storage and public/read-only functions:

SIP token templates

SIP-010 and SIP-009 templates implement all required trait functions. They ship without (impl-trait …) so testnet deploy succeeds.
Never use bare trait names like (impl-trait 'sip-010-trait). Use the full mainnet path or omit for testnet. See the comment in each SIP template for the exact mainnet line.
Mainnet trait addresses:

Contract requirements

For contracts that depend on external contracts (like sBTC), add requirements:
SIP templates automatically add trait requirements to Clarinet.toml for simnet type-checking.

Key concepts

sBTC Integration

Contracts using sBTC require the sBTC contract as a dependency:
  • Uses restrict-assets? for post-conditions
  • Transfers sBTC using the official token contract

Data Storage

  • Maps: Store structured data with metadata
  • Data variables: Track counters and global state
  • Constants: Define immutable values

Access Control

  • CONTRACT_OWNER for privileged operations
  • asserts! for authorization checks
  • tx-sender vs contract-caller for security

Read-Only Functions

  • Query contract state without transactions
  • Return Optional types for safe lookups
See SIP standards for trait tables, hook examples, and impl-trait rules.

Testing contracts

Write tests in contracts/tests/ using the Clarinet SDK with the clarinet Vitest environment:
Full patterns, ABI caching, and frontend Vitest coverage live in Testing.