Skip to content

StxScript

A TypeScript-inspired transpiler for Clarity smart contracts on the Stacks blockchain.

Write contracts with familiar syntax. Get valid, optimized Clarity output.

Quick Example

StxScript:

const TOKEN_NAME: string = "MyToken";
const MAX_SUPPLY: uint = 1000000u;

let total_supply: uint = 0u;
map balances<principal, uint>;

@public
function mint(amount: uint): Response<bool, uint> {
    if (total_supply + amount > MAX_SUPPLY) {
        return err(1u);
    }
    total_supply = total_supply + amount;
    return ok(true);
}

@readonly
function get_balance(account: principal): uint {
    match balances.get(account) {
        some(balance) => balance,
        none => 0u
    }
}

Generated Clarity:

(define-constant TOKEN_NAME u"MyToken")
(define-constant MAX_SUPPLY u1000000)
(define-data-var total_supply uint u0)
(define-map balances principal uint)

(define-public (mint (amount uint))
  (if (> (+ (var-get total_supply) amount) MAX_SUPPLY)
    (err u1)
    (begin
      (var-set total_supply (+ (var-get total_supply) amount))
      (ok true))))

(define-read-only (get-balance (account principal))
  (default-to u0 (map-get? balances account)))

Getting Started

pip install stxscript
stxscript new my-token --template token
cd my-token
stxscript build src/main.stx build/main.clar

See the Getting Started guide for a full walkthrough.

Documentation Sections

Guide

Step-by-step guides for common workflows:

Language

Complete language reference, expanded with explanations and Clarity output:

Reference

Lookup tables and API documentation:

Tooling

Developer tools and IDE integration:

Features

  • Familiar Syntax - TypeScript-inspired, C-style syntax
  • Type Safety - Static types with inference, checked at compile time
  • Semantic Analysis - Scope validation, trait compliance, type checking
  • Zero Runtime - Compiles to native Clarity with no overhead
  • Modern Tooling - Formatter, linter, LSP, VS Code extension
  • Testing Framework - Mock blockchain, contract assertions
  • Package Manager - Semantic versioning, dependency resolution

Version

Current version: 0.3.0