Project Structure
Understand the complete structure and configuration of a Clarinet project.
A Clarinet project uses a structure that separates contracts, tests, and configuration. Understanding this structure helps you organize code and configure your development tools.
Core project layout
Every Clarinet project contains these directories and files:
- my-project/
- .vscode/
- contracts/
- main.clar
- trait.clar
- deployments/
- settings/
- Devnet.toml
- Mainnet.toml
- Testnet.toml
- tests/
- main.test.ts
- .gitignore
- Clarinet.toml
- package.json
- tsconfig.json
- vitest.config.jsThe project manifest
Clarinet.toml
The Clarinet.toml file defines project metadata and tracks all contracts:
clarinet contract new writes these two keys for you. Clarinet v3.24.1 accepts clarity_version values 1 through 6.
The manifest handles:
Contract registration: Every contract must be listed here
Stacks epoch and Clarity version: Specifies Clarity version and epoch for each contract
Boot sequence: Lists contracts to deploy on
clarinet devnet start
Epoch configuration
Set the epoch per contract, either to a specific version or to the current mainnet epoch:
"latest" means the epoch active on mainnet, which Clarinet v3.24.1 pins to 4.0. It is not the newest epoch the Clarity VM knows about, so a contract marked "latest" deploys with the features mainnet has today.
The two keys depend on each other:
epochset,clarity_versionomitted: Clarinet uses the default Clarity version for that epoch. Epoch 4.0 defaults to Clarity 6.Both omitted: Clarinet falls back to epoch 2.05 and Clarity 1, which rejects most current syntax. Set both.
clarity_versionnewer than the epoch supports:clarinet checkstops withClarity 6 can not be used with 3.4(the message names your values).
A contract that calls pox-5 or implements its signer-manager-trait needs epoch = 4.0 or "latest", because pox-5 does not exist in earlier epochs; any clarity_version up to 6 compiles in that epoch. Pick Clarity 6 when the contract uses what Clarity 6 added: the with-staking and with-pox allowances for restrict-assets? and as-contract?, get-bitcoin-tx-output?, verify-merkle-proof, ed25519-verify, secp256k1-decompress?, or variadic concat. In Clarity 4 and 5 contracts the allowance keeps its old spelling, with-stacking; the renamed_builtin lint in clarinet check flags it once the contract's clarity_version is 6.
Testing infrastructure
Package configuration
The package.json defines your testing environment and dependencies:
@stacks/clarinet-sdk
WebAssembly-compiled Clarinet for Node.js
@stacks/transactions
Clarity value manipulation in TypeScript
vitest
Testing framework with native TypeScript support
vitest-environment-clarinet
Simnet bootstrapping for tests
Vitest configuration
The vitest.config.ts (or .js) configures the testing framework. Import defineConfig from vitest/config, not from vite. This configuration works with Vitest v4 and later.
This configuration sets up:
Clarinet environment: Automatic
simnetsetup for each testSingle fork mode: Efficient test execution with proper isolation
Coverage tracking: Generate reports in multiple formats
Custom setup: Add project-specific test utilities
TypeScript configuration
The tsconfig.json provides TypeScript support:
Setting the include property as shown makes TypeScript pick up the helpers defined in the Clarinet SDK package along with your tests.
Network configurations
Environment settings
Each network has its own configuration file in the settings directory:
These settings control:
Network ports: API, RPC, and explorer endpoints
Account configuration: Test wallets with STX balances
Chain parameters: Network-specific blockchain settings
Common issues
Last updated
Was this helpful?