Clarity on Stacks

A decidable, interpreted smart-contract language: LISP syntax, explicit responses, post-conditions and Bitcoin settlement.

10 min read·5 quiz questions

Decidable and interpreted

Clarity ships source code on-chain and interprets it — there is no compiler and no bytecode. The language is decidable: no unbounded loops or recursion, so cost and outcome are analysable before execution. That is a deliberate trade of expressiveness for predictability.

  • What you read on the explorer is exactly what runs.
  • Static analysis can determine runtime cost bounds.
  • No reentrancy in the Solidity sense: calls are restricted and explicit.

Syntax and definitions

Clarity is LISP-like: every expression is a parenthesised list. define-public functions are callable and must return a response, define-read-only functions cannot mutate, define-data-var and define-map hold state, and define-constant fixes values.

  • (define-public (stake (amount uint)) ...) — callable entry point.
  • (define-map balances principal uint) — keyed state.
  • principal is the address type for users and contracts.

Responses and explicit errors

Public functions return (ok value) or (err code). There are no silent failures and no exceptions: unwrap!, try! and asserts! make the failure path visible in the code. Returning err rolls back the function's state changes.

Bitcoin awareness and post-conditions

Stacks settles on Bitcoin, so contracts can read burn-block-height and Bitcoin block headers. Wallets add post-conditions: the client declares which asset movements it will accept, and the transaction aborts if the contract tries anything else — a user-side protection Solidity has no direct equivalent of.

Key terms

Decidable
Property letting you determine a program's cost and outcome without running it.
principal
Clarity type for an address: a standard user or a contract.
Response
(ok v) / (err code) return type required of public functions.
Post-condition
Client-declared constraint on asset transfers; violations abort the tx.
burn-block-height
Current Bitcoin block height, readable from Clarity.

Chapter quiz

5 questions · pass mark 75%
  1. 1. What is deployed on-chain when you publish a Clarity contract?

  2. 2. Clarity is decidable, which means…

  3. 3. A define-public function must return…

  4. 4. A post-condition protects the user by…

  5. 5. Why can a Clarity contract read burn-block-height?

Answer every question to submit. Progress for clarity-on-stacks is saved in this browser.