Validation and Analysis

Clarinet provides tools for validating, analyzing, linting, and debugging your smart contracts. From static type checking to real-time cost analysis, you can check your contracts for errors and costs before deployment.
Contract validation spans static analysis, runtime debugging, and cost optimization.
Understanding contract validation
Static analysis vs. runtime debugging
Catches issues before deployment
Reveals behavior during execution
Flags type mismatches and syntax errors
Shows actual execution costs
Ensures trait compliance
Exposes state changes and side effects
Detects undefined variables
Highlights transaction flow
Validates function signatures
Surfaces performance bottlenecks
Static analysis
Run validation with clarinet check:
Successful output resembles:
When validation fails, Clarinet prints diagnostics:
Run basic checks
Use clarinet check to validate your contracts and catch type/syntax errors before deployment.
Check a specific contract
Focus validation during development on a single contract file:
Clarinet applies the [linter] settings from the Clarinet.toml given with --manifest-path, or from the nearest Clarinet.toml above the current directory. If there is no manifest, it uses the default lints. The project's include and exclude filters do not apply to a file you name explicitly.
Integrate into CI
Automate validation in continuous integration pipelines. Example GitHub Actions workflow:
Validation scope
Clarinet validates multiple aspects of your contracts:
Type safety
Function parameters, return values, variable types
Trait compliance
Implementation matches trait definitions
Response consistency
ok/err branches return the same types
Variable scope
Variables defined before use
Function visibility
Proper use of public, private, and read-only
Linter analysis
Clarinet includes a built-in linter as part of clarinet check that flags common mistakes, inefficiencies, and unused code in Clarity contracts.
Clarinet 4.0 has 24 lints in five groups:
correctness: code that is certainly wrongunused: dead codeperf: inefficient codesafety: code that might not do what you intendedstyle: naming conventions
You can configure each lint on its own or through its group. The correctness lints are the exception: you cannot configure them.
call_checker
Detects calls that pass the wrong number of arguments to a function.
correctness
unused_binding
Detects unused function parameters and let bindings.
unused
unused_const
Detects unused define-constant declarations.
unused
unused_data_var
Detects define-data-var declarations that are never used, never read, or never written (a value that is never written can be a constant).
unused
unused_map
Detects define-map declarations that are never accessed.
unused
unused_private_fn
Detects private functions that are never called.
unused
unused_token
Detects fungible and non-fungible tokens that are never minted.
unused
unused_trait
Detects traits imported with use-trait that are never used as parameter types.
unused
flatten_variadic
Suggests flattening nested calls to a variadic function, for example (+ a (+ b c)) to (+ a b c). From Clarity 6 this includes concat, which became variadic.
perf
unnecessary_as_max_len
Detects unnecessary as-max-len? calls.
perf
unnecessary_public
Detects public functions that could be read-only because they change no state.
perf
unnecessary_tuple
Detects tuples with a single field.
perf
at_block
Warns about uses of at-block, which is proposed for removal.
safety
error_const
Checks that every ERR_ constant is an (err ...) value and that no two ERR_ constants share a value.
safety
noop
Detects expressions that have no effect, such as (is-eq 1).
safety
panic
Warns about unwrap-panic and unwrap-err-panic.
safety
renamed_builtin
Detects calls to a builtin that a later Clarity version renamed. The one rename today is with-stacking to with-staking (Clarity 6); the old spelling keeps working in Clarity 4 and 5 contracts.
safety
case_binding
Enforces kebab-case on let bindings and function argument names.
style
case_const
Enforces SCREAMING_SNAKE_CASE on constants.
style
case_data_var
Enforces kebab-case on data variables.
style
case_fn
Enforces kebab-case on function names.
style
case_map
Enforces kebab-case on maps.
style
case_token
Enforces kebab-case on fungible and non-fungible token names.
style
case_trait
Enforces kebab-case on trait names.
style
Bypassing the linter
Code can look unused when it is used in a way the linter can't see. Examples include private functions used only in tests, or bindings whose evaluation has side effects.
Clarinet follows a convention similar to Rust: the linter allows identifiers with a trailing _ (a leading _ does not work) to be unused, but other lints still apply to them.
Individual lints can also be disabled for a specific line using Clarity's annotation syntax:
Configuration
By default, lints in the unused, perf and safety groups report at the warning level and style lints at the notice level. Change the level per lint or per group in the [linter] section of Clarinet.toml.
Lints in the correctness group always report at the error level and reject the contract. [linter] settings do not change them: call_checker = "warning", correctness = false and all = false have no effect on these lints.
Each value is a level ("error", "warning" or "notice"), false or "off" to turn the lint off, or true or "on" to turn it on at its default level. A lint that is already on keeps its current level, so style = true gives notices, not warnings. To get warnings, set "warning" explicitly.
Files to analyze
Individual lint configuration
Lint group configuration
Runtime analysis
The Clarinet console has commands for inspecting behavior during execution.
Cost analysis with ::toggle_costs
Turn on automatic cost display after every expression:
Execution tracing with ::trace
Trace function calls to understand execution flow:
Interactive debugging with ::debug
Set breakpoints and step through execution:
Common navigation commands:
Using ::get_costs for targeted analysis
Spotting costly operations with ::trace
Review the trace for loops with high iteration counts, nested map/filter operations, repeated contract calls, and large data structure manipulations.
Debugging workflows
Run ::debug to pause execution and show the current source location:
Analyzing failed transactions with ::trace
Using ::encode and ::decode for inspection
Testing time-dependent logic
Last updated
Was this helpful?