Contents
- Creating contracts
- Sample contract
- SIP token templates
- Contract requirements
- Key concepts
- Testing contracts
Creating contracts
Use the CLI to add new contracts to your project:.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.
Mainnet trait addresses:
Contract requirements
For contracts that depend on external contracts (like sBTC), add requirements: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_OWNERfor privileged operationsasserts!for authorization checkstx-sendervscontract-callerfor security
Read-Only Functions
- Query contract state without transactions
- Return
Optionaltypes for safe lookups
impl-trait rules.
Testing contracts
Write tests incontracts/tests/ using the Clarinet SDK with the clarinet Vitest environment: