Skip to content
stxscript. GitHub

Home · Language reference

Every construct, and the Clarity it emits.

The contract StxScript makes with you: read a construct on the left, know exactly what Clarity appears on the right. Where the mapping is idiomatic rather than one-to-one, the row says so. Nothing here invents runtime behavior.

Declarations

StxScriptClarity
const NAME: uint = 1u; (define-constant NAME u1)
let total: uint = 0u; (define-data-var total uint u0)
type Amount = uint; — (alias; erased at codegen)
map balances<principal, uint>; (define-map balances principal uint)

Functions

StxScriptClarity
@public function f() {} (define-public (f) ...)
@readonly function g() {} (define-read-only (g) ...)
function h() {} (no decorator) (define-private (h) ...)
(x: uint) => x * 2u lambda used with fold / map
function id<T>(x: T): T monomorphized to concrete types

Types

StxScriptClarity
uint / int / bool uint / int / bool
string (string-ascii N) / (string-utf8 N)
principal principal
buffer<N> (buff N)
Optional<T> (optional T)
Response<T, E> (response T E)
List<T> (list N T)
{ x: uint, y: uint } (tuple (x uint) (y uint))

Control flow & errors

StxScriptClarity
if (c) { a } else { b } (if c a b)
match opt { some(v) => ..., none => ... } (match opt v ... ...)
value ?? fallback (default-to fallback value)
try!(expr) (try! expr)
ok(v) / err(e) (ok v) / (err e)

Maps, traits, bitwise

StxScriptClarity
balances.get(k) (map-get? balances k)
balances.set(k, v) (map-set balances k v)
balances.delete(k) (map-delete balances k)
@implements(Token) (impl-trait ...Token) + conformance check
a & b | c ^ d (bit-and a b) (bit-or b c) (bit-xor c d)
x << n / x >> n (bit-shift-left x n) / (bit-shift-right x n)

See it end to end

The homepage shows a full token contract in StxScript beside the Clarity it compiles to. The pipeline page explains how codegen stays deterministic.