Project Development
Clarinet streamlines the entire lifecycle of Clarity smart contract development. From project initialization to contract management and code formatting, you'll have the tools needed for professional workflows.
Creating a new project
The clarinet new command creates a complete project structure with all necessary configuration files:
$ clarinet new my-defi-app--disable-telemetry
Opt out of telemetry collection
clarinet new my-app --disable-telemetry
For a deeper look at what Clarinet generates, see the project structure guide.
Managing contracts
Creating new contracts
The clarinet contract new command generates both a contract file and a matching test file:
$ clarinet contract new token
Created file contracts/token.clar
Created file tests/token.test.ts
Updated Clarinet.tomlThe generated contract includes a minimal template:
;; token
;; <add a description here>
;; constants
;;
;; data vars
;;
;; data maps
;;
;; public functions
;;
;; read only functions
;;
;; private functions
;;Removing contracts
Clean up unused contracts with the rm command:
$ clarinet contract rm old-token
Removed file contracts/old-token.clar
Removed file tests/old-token.test.ts
Updated Clarinet.tomlChecking project contract syntax
Validate your entire project setup:
$ clarinet check
✔ 3 contracts checkedCheck specific contracts:
$ clarinet check contracts/token.clar
✔ contracts/token.clar Syntax of contract successfully checkedCode formatting
Clarinet includes a formatter to maintain consistent style across your project.
Format all contracts in your project:
$ clarinet format --in-place
Formatted 5 contractsFormatting options
Customize formatting to match your team's style guide:
--dry-run
Preview changes without modifying files
clarinet format --dry-run
--in-place
Replace file contents (required for actual formatting)
clarinet format --in-place
--max-line-length
Set maximum line length
clarinet format --max-line-length 100
--indent
Set indentation size
clarinet format --indent 2
--tabs
Use tabs instead of spaces
clarinet format --tabs
Format single files
$ clarinet format contracts/messy-contract.clar --in-placeFormat specific contracts with glob patterns:
$ clarinet format contracts/token*.clar --in-placeProject configuration
Working with requirements
Add mainnet contracts as dependencies:
$ clarinet requirements add SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait
Added requirement SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait
Updated Clarinet.tomlClarinet adds the dependency to Clarinet.toml:
[project]
requirements = [
{ contract_id = "SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait" }
]You can now implement traits from mainnet contracts:
(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
(define-non-fungible-token my-nft uint)
;; ... implement required functionsLast updated
Was this helpful?
