Tact Language Documentation

repository·main·Indexed 20 days ago

https://github.com/tact-lang/tact

Tact is a next-generation smart contract programming language for the TON Blockchain featuring a TypeScript-like syntax, strong type system, and automatic (de)serialization. The documentation covers the @tact-lang/compiler package, tooling such as tact-fmt and unboc, development environments like Blueprint and tact-template, and a strict TypeScript styleguide for ensuring security and correctness.

Tokens
140.8K
Snippets
475
Records
574
Agent score
69%

What's inside Tact

  1. Overview of Misti Static Analyzer

    main

    Misti is a static program analysis tool designed for Tact contracts. It scans code for bugs and security flaws by examining structure and syntax without executing the code.

    Key capabilities include:

    • Static Program Analysis: Early detection of issues before production.
    • Custom Detectors: Ability to create specialized detectors to identify specific vulnerabilities.
    • CI/CD Integration: Support for automated code quality checks within continuous integration pipelines.
  2. Features of the Tact VS Code extension

    main

    The Tact VS Code extension provides a comprehensive development environment with the following features:

    • Code Intelligence: Semantic syntax highlighting, code completion (with auto-import, postfix completion, and imports completion), and signature help for calls, initOf, and struct initialization.
    • Navigation: Go to definition, implementation, and type definition; find all references; workspace symbol search; and symbol renaming.
    • Information & Hints: Types and documentation on hover, inlay hints for types and parameter names, and code lenses for implementation/reference counts.
    • Diagnostics & Analysis: On-the-fly inspections with quick fixes, gas estimates for assembly functions, and integration with the Tact compiler and Misti static analyzer.
    • Project Management: Build and test projects based on Blueprint and Tact Template.
  3. Explore the Tact Reference section

    main

    The Tact Reference section provides the technical foundation for using the language, organized into four main areas:

    • Core library: A list of auto-included functions, traits, and constructs with usage examples.
    • Standard libraries: Documentation on how to use bundled libraries and their specific contents.
    • Specification: A detailed grammar specification for understanding all possible syntax.
    • Evolution: Information regarding language semantics, future developments, and the changelog.
  4. Features of the Tact JetBrains plugin

    main

    The Tact plugin enhances the development experience with the following capabilities:

    • Navigation & Search: Go to definition, implementation, and type definition; find all references; workspace symbol search; and symbol renaming.
    • Code Intelligence: Code completion, snippets, imports completion, and signature help (inside calls and initOf).
    • Visual Aids: Semantic syntax highlighting, types and documentation on hover, inlay hints (for types and parameter names), and lenses (showing usage counts and VCS author).
    • Diagnostics & Refactoring: On-the-fly inspections with quick fixes.
    • Project Management: Build single contracts or entire projects using tact.config.json via Run configurations.
    • Formatting: Code formatting available via keyboard shortcuts or on save.
  5. Explore Tact language features

    main

    Tact is a smart contract programming language for the TON Blockchain with the following key features:

    • TypeScript-like Syntax: Familiar and user-friendly syntax.
    • Strong Type System: Built-in support for Structs, Messages, and maps.
    • Automatic (De)serialization: Handles incoming messages and data structures automatically.
    • Automatic Routing: Manages internal, external, and bounced messages.
    • Traits: Reusable and composable behaviors similar to interfaces or mixins.
    • TypeScript Wrappers: Generates single-file TypeScript wrappers for interacting with compiled contracts, providing type definitions, serialization functions (storeStructureName(), loadStructureName()), and contract helper classes.
  6. Explore the Tact ecosystem tools

    main

    The Tact ecosystem includes official and community-made tools designed for Tact development or for interacting with the language. Key tools include:

    • TypeScript: Integration for type-safe development.
    • VS Code Extension: Official extension for the Visual Studio Code IDE.
    • JetBrains IDEs Plugin: Plugin for JetBrains IDEs (e.g., IntelliJ IDEA, WebStorm).
    • Misti Static Analyzer: A tool for static analysis of Tact code.
  7. Overview of Tact operators and precedence

    main

    Tact uses operators to transform data. Operators follow a specific order of precedence, which determines how expressions are evaluated when multiple operators are present. If an expression is ambiguous, Tact prefers operators with higher precedence.

    Important: No Implicit Type Conversions Tact does not perform implicit type conversions. You cannot use operators to add or compare values of different types without explicitly casting them using standard library functions (e.g., Int.toString()).

  8. Understand transaction phases and state updates

    main

    TON transactions consist of multiple phases. Outbound messages are evaluated during the compute phase but are not actually sent until the action phase.

    If the compute phase fails, persistent data (registers c4) and actions (registers c5) will not be updated. If you need to manually save state despite potential failures, use the commit() function.

  9. Handle outbound message errors with SendIgnoreErrors

    main

    The SendIgnoreErrors flag in the mode field allows a message to be skipped if an error occurs during outbound processing, rather than causing the entire transaction to fail.

    Common exit codes that SendIgnoreErrors can suppress include:

    • 36: Invalid destination address in outbound message
    • 37: Not enough Toncoin
    • 39: Outbound message doesn't fit into a cell
    • 40: Cannot process a message
  10. Understand Tact assembly function stack notation

    main

    Tact uses a special "stack notation" to describe the state of the stack before and after an asm fun (assembly function) is executed. This notation helps map TVM instructions to Tact parameters and return values.

    Notation Components

    • Types: Parameters and return values are listed with their types (e.g., x:Int, y:Int → z:Int).
    • Stack Registers: Represented by s0, s1, etc., showing the position of values on the stack.
    • Directional Arrows: separates input stack state from output stack state.
    • Mapping: s0 typically represents the top of the stack.

    Example Mapping

    // x:Int, y:Int → z:Int
    // ————————————————————
    // s1     s0    → s0
    // ↑      ↑      ↑

    In this example, y is at the top of the stack (s0), x is second to the top (s1), and the result z is pushed onto the top of the stack (s0).

    // Example of stack notation used in documentation
    // x:Int, y:Int → z:Int
    // ————————————————————
    // s1     s0    → s0
    // ↑      ↑      ↑
  11. Define contract constants

    main

    Constants are calculated at compile-time and cannot change during execution. Unlike state variables, constants do not consume space in the persistent state; they are stored directly in the contract's code Cell.

    // global constants
    const GlobalConst1: Int = 1000 + ton("42") + pow(10, 9);
    
    contract Example {
        // contract constants
        const ContractConst1: Int = 2000 + ton("43") + pow(10, 9);
    
        const StateUnpaid: Int = 0;
        const StatePaid: Int = 1;
    
        get fun sum(): Int {
            return GlobalConst1 + self.ContractConst1 + self.StatePaid;
        }
    }