# StxScript > A TypeScript-inspired transpiler for writing Clarity smart contracts on the Stacks blockchain. Write contracts with familiar syntax. Get valid, optimized, audit-ready Clarity output. ## What StxScript Is StxScript is a source language for Clarity. You write `.stx` files with TypeScript-flavored syntax — explicit types, decorators, generics, match expressions — and the transpiler emits `.clar` files that deploy unchanged to the Stacks blockchain. It is not a new VM. It is not a competing chain. There is no token, no protocol, no network. The Stacks blockchain runs the Clarity that StxScript produces; StxScript itself runs only at build time. The project ships as a single pip package (`pip install stxscript`). The package contains the CLI (`stxscript`), the language server (`stxscript-lsp`), the formatter, the linter, and the project scaffolder. Source is at https://github.com/cryptuon/stxscript and is MIT-licensed. ## Architecture (verified from the README) The transpiler is a four-stage pipeline: 1. **Parsing** — a Lark-based LALR grammar parses `.stx` source. 2. **AST generation** — a typed abstract syntax tree captures the structure. 3. **Semantic analysis** — type checking, scope validation, trait compliance. 4. **Code generation** — emits indented, idiomatic Clarity. The current release is v0.3.0 with 146 passing tests. ## Language Features Every StxScript feature has a Clarity counterpart. The transpiler never produces Clarity that the runtime would reject. - **Variables and constants**: `let` and `const` with explicit types. - **Functions**: `@public`, `@readonly` decorators map to `define-public` / `define-read-only`. Plain `function` is private. - **Type system**: `int`, `uint`, `bool`, `string`, `principal`, `buffer`, `Optional`, `Response`, `List`, maps, tuples. - **Type aliases and generics**: `type Amount = uint;`, `function identity(x: T): T`. Generics monomorphize at compile time. - **Control flow**: `if/else`, `match`, `for`, `while`. Match destructures Optional and Response. - **Lambda expressions**: `(x: uint) => x * 2u`. - **Traits and interfaces**: `trait` definitions, `@implements(Token)` contracts. - **Maps**: `map balances;` with `.get`/`.set`/`.delete`. - **Error handling**: `Response` types, `!` unwrap, `??` default, `try!`. - **Imports**: module system, cross-contract calls. - **Bitwise**: `&`, `|`, `^`, `~`, `<<`, `>>`. ## CLI Commands (verbatim from the README) | Command | Description | |---------|-------------| | `stxscript build [output]` | Transpile StxScript to Clarity | | `stxscript fmt ` | Format code | | `stxscript lint ` | Static analysis | | `stxscript check ` | Syntax validation | | `stxscript new ` | Create new project (basic/token/nft/defi templates) | | `stxscript watch ` | Watch mode with auto-rebuild | | `stxscript doc ` | Generate documentation | | `stxscript test [path]` | Run contract tests | | `stxscript pkg ` | Package management (init/add/remove/install/list) | ## Editor Support - **VS Code extension**: syntax highlighting, snippets, integrated LSP. - **LSP server**: diagnostics, autocomplete, hover info, go-to-definition. - **Vim/Neovim, Sublime, Emacs**: LSP client configuration documented. Start the language server directly with `stxscript-lsp`. ## Who Should Use It - Developers coming from TypeScript, Rust, or Swift who want to write Stacks contracts without learning Lisp surface syntax first. - Teams adopting Clarity who want a checked type system and an LSP-driven editor experience. - Engineers who prefer static analysis (`stxscript check`, `stxscript lint`) before deploy. - Anyone who likes `fmt`, `lint`, `watch`, `test`, and `new` as standard tooling. ## Honest Comparisons - **vs writing Clarity directly**: Raw Clarity is the honest baseline. StxScript adds a source language, type system, and toolchain — at the cost of a build step. Pick StxScript when DX savings beat the cost of an extra layer. - **alongside Clarinet**: Clarinet is the Stacks dev environment / test runner. StxScript produces Clarity that Clarinet runs. They compose; they do not compete. ## Pages - / - /features/ - /how-it-works/ - /language/ - /quickstart/ - /cli/ - /use-cases/ - /use-cases/typescript-teams/ - /use-cases/token-and-nft-contracts/ - /use-cases/typed-clarity-migration/ - /use-cases/editor-driven-development/ - /faq/ - /about/ - /blog/ - /blog/reading-the-clarity-output/ - /blog/type-inference-and-clarity-mapping/ - /blog/first-stacks-contract-in-stxscript/ - /compare/clarity/ - /compare/clarinet/ - /contact/ - /404/ - /rss.xml - /llms.txt - /llms-full.txt ## Out of scope (not a feature) - No tokenomics. StxScript is a developer tool, not a protocol. - No hosted service / pricing tier. Open source, pip install, MIT licensed. - No competing VM or runtime. The output is Clarity, executed by Stacks.