|
1 | 1 | --- |
2 | | -title: "Tolk" |
| 2 | +title: "Tolk — the language for TON" |
3 | 3 | sidebarTitle: "Overview" |
4 | 4 | --- |
5 | 5 |
|
6 | | -**Tolk** is a next-generation language for developing smart contracts on TON. It replaces FunC with an expressive syntax, a robust type system, and built-in serialization — while generating highly optimized assembly code. |
| 6 | +import { Aside } from '/snippets/aside.jsx'; |
7 | 7 |
|
8 | | -This page introduces Tolk's _core features, explains how it compares to FunC, and outlines how to get started with the language_ — whether you're migrating from FunC or writing smart contracts from scratch. |
| 8 | +**Tolk** is a statically typed language designed for TON smart contracts. |
9 | 9 |
|
10 | | -## Why choose Tolk |
| 10 | +It provides declarative structures, automatic cell serialization, first-class message handling, and a modern development experience. |
11 | 11 |
|
12 | | -1. Clean, expressive syntax inspired by TypeScript and Rust. |
13 | | -1. Built-in primitives for TON, including structures, auto‑packing to/from cells, pattern matching, and first-class message handling. |
14 | | -1. Strong static type system with _null safety, type aliases, union types, and generics_ for safer, clearer code. |
15 | | -1. Gas‑efficient by design — see [benchmarks](https://github.com/ton-blockchain/tolk-bench) and [comparison](/languages/tolk/from-func/tolk-vs-func); features like **[Lazy loading](/languages/tolk/features/lazy-loading)** can reduce costs. |
16 | | -1. Low-level control is available when needed, with direct access to the TVM stack and instructions. |
17 | | - |
18 | | -## Getting started with Tolk |
19 | | - |
20 | | -To get familiar with Tolk, follow the ["Your first smart contract"](/contract-dev/first-smart-contract) article. |
21 | | -It contains required steps for setting up an environment and creating a counter contract from a template, as well as explanation of every step. |
22 | | - |
23 | | -Later on, return to this section and start exploring [Basic syntax](/languages/tolk/basic-syntax), [Type system](/languages/tolk/types/list-of-types), |
24 | | -and other points from the left menu. |
25 | | - |
26 | | -## How to migrate from FunC |
27 | | - |
28 | | -If you've written contracts in FunC, migrating to Tolk is straightforward — and often results in simpler, more maintainable code. |
29 | | - |
30 | | -1. Try building a basic contract in Tolk — for example, a counter using `npm create ton@latest`. You'll quickly notice the shift from stack logic to expressive constructs with structured types, unions, pattern matching, `toCell()`, and more. |
31 | | -1. Explore the [Tolk vs FunC benchmarks](https://github.com/ton-blockchain/tolk-bench). These are real-world contracts (Jetton, NFT, Wallet, etc.) migrated from FunC — same logic, but expressed in a cleaner, more expressive style. |
32 | | -1. Read [Tolk vs FunC](/languages/tolk/from-func/tolk-vs-func) for a quick comparison of syntax and concepts. |
33 | | -1. Use the [FunC-to-Tolk converter](/languages/tolk/from-func/converter) to migrate existing codebases incrementally. |
34 | | - |
35 | | -## Example of a basic Tolk smart contract: |
| 12 | +The language compiles to TVM (TON virtual machine) with zero overhead and full control over execution. |
36 | 13 |
|
37 | 14 | ```tolk |
38 | | -import "utils" |
39 | | -
|
40 | | -struct Storage { |
41 | | - counter: int32 |
42 | | -} |
43 | | -
|
44 | | -fun Storage.load() { |
45 | | - return Storage.fromCell(contract.getData()); |
46 | | -} |
| 15 | +type AllowedMessage = CounterIncrement | CounterReset |
47 | 16 |
|
48 | 17 | fun onInternalMessage(in: InMessage) { |
49 | | - // ... |
| 18 | + val msg = lazy AllowedMessage.fromSlice(in.body); |
| 19 | + match (msg) { |
| 20 | + CounterIncrement => { ... } |
| 21 | + CounterReset => { ... } |
| 22 | + } |
50 | 23 | } |
51 | 24 |
|
52 | | -get fun currentCounter(): int { |
| 25 | +get fun currentCounter() { |
53 | 26 | val storage = lazy Storage.load(); |
54 | 27 | return storage.counter; |
55 | 28 | } |
56 | 29 | ``` |
57 | 30 |
|
58 | | -<details> |
59 | | - <summary><b>Equivalent implementation in FunC</b></summary> |
| 31 | +## Key features |
60 | 32 |
|
61 | | - ```func |
62 | | - #include "utils.fc"; |
| 33 | +Tolk offers high-level readability while remaining low-level in nature: |
63 | 34 |
|
64 | | - global int ctx_counter; |
| 35 | +- a robust type system to express any cell layout in TON |
| 36 | +- lazy loading: unused fields are skipped automatically |
| 37 | +- unified message composition and deployment |
| 38 | +- a gas-efficient compiler targeting the Fift assembler |
| 39 | +- friendly tooling and IDE integration |
65 | 40 |
|
66 | | - int load_data() impure { |
67 | | - slice cs = get_data().begin_parse(); |
68 | | - ctx_counter = cs~load_uint(32); |
69 | | - } |
| 41 | +<Aside type="tip"> |
| 42 | + Tolk is fully compatible with existing TON standards and contracts. |
| 43 | +</Aside> |
70 | 44 |
|
71 | | - () recv_internal(int msg_value, cell msg_full, slice msg_body) impure { |
72 | | - slice cs = msg_full.begin_parse(); |
73 | | - int flags = cs~load_uint(4); |
74 | | - if (flags & 1) { |
75 | | - return (); |
76 | | - } |
77 | | - ... |
78 | | - } |
| 45 | +## Tolk is a replacement for FunC |
| 46 | + |
| 47 | +Tolk started as an evolution of FunC and is now the recommended language for TON smart contracts. |
| 48 | + |
| 49 | +If you are migrating from FunC: |
| 50 | + |
| 51 | +- Look through [benchmarks](https://github.com/ton-blockchain/tolk-bench): notice **30–50% lower gas fees**. |
| 52 | +- Scan the page [Tolk vs FunC](/languages/tolk/from-func/tolk-vs-func) to get the overall picture. |
| 53 | +- Use the [FunC-to-Tolk converter](/languages/tolk/from-func/converter) to migrate existing projects. |
| 54 | + |
| 55 | +## Quick start |
| 56 | + |
| 57 | +1. Run the command: |
79 | 58 |
|
80 | | - int currentCounter() method_id { |
81 | | - load_data(); ;; fills global variables |
82 | | - return ctx_counter; |
83 | | - } |
84 | | - ``` |
85 | | -</details> |
| 59 | + ```bash |
| 60 | + npm create ton@latest |
| 61 | + ``` |
86 | 62 |
|
87 | | -[FunC to Tolk converter](https://github.com/ton-blockchain/convert-func-to-tolk). |
| 63 | +1. Enter a project name and choose "simple counter contract". |
88 | 64 |
|
89 | | -## Tooling around Tolk |
| 65 | +1. Follow the ["Your first smart contract"](/contract-dev/first-smart-contract) article |
| 66 | + to get explanations. |
90 | 67 |
|
91 | | -A set of tools is available to support development with Tolk — including IDE support, language services, and migration utilities. |
| 68 | +## IDE support |
92 | 69 |
|
93 | | -- [JetBrains IDE plugin](https://github.com/ton-blockchain/intellij-ton). Adds support for Tolk, FunC, Fift, and TL-B. |
94 | | -- [VS Code extension](https://marketplace.visualstudio.com/items?itemName=ton-core.vscode-ton). Provides Tolk support and language features. |
95 | | -- [Language server](https://github.com/ton-blockchain/ton-language-server). Works with any LSP-compatible editor. |
96 | | -- [FunC-to-Tolk converter](https://github.com/ton-blockchain/convert-func-to-tolk). Migrates entire projects with a single `npx` command. |
97 | | -- [`tolk-js`](https://github.com/ton-blockchain/tolk-js). WASM wrapper for the Tolk compiler is integrated into Blueprint. |
| 70 | +All major IDEs support syntax highlighting and code completion: |
98 | 71 |
|
99 | | -The Tolk compiler itself lives in the `ton` [repository](https://github.com/ton-blockchain/ton). |
| 72 | +1. **JetBrains IDEs** (WebStorm, CLion, etc.) — via the [plugin](https://github.com/ton-blockchain/intellij-ton)<br /> |
| 73 | + \=> search for "TON" in Marketplace and install |
100 | 74 |
|
101 | | -## Is Tolk production-ready? |
| 75 | +1. **VS Code** — via the [TON extension](https://marketplace.visualstudio.com/items?itemName=ton-core.vscode-ton)<br /> |
| 76 | + \=> search for "TON" in Marketplace and install |
102 | 77 |
|
103 | | -All contracts in the [Tolk vs FunC benchmarks](https://github.com/ton-blockchain/tolk-bench) pass the same test suites as their FunC counterparts — with identical logic and behavior. |
| 78 | +1. **Cursor, Windsurf, and other** editors — via the [language server](https://github.com/ton-blockchain/ton-language-server)<br /> |
| 79 | + \=> install from the `.vsix` file or a command palette |
104 | 80 |
|
105 | | -Tolk is under active development, and some edge cases may still occur. Evaluate it for your use case and ensure thorough testing before production deployment. |
| 81 | +## Where to go next |
106 | 82 |
|
107 | | -Regardless of the language, well-tested code is the key to building reliable smart contracts. |
| 83 | +Recommended starting points: |
108 | 84 |
|
109 | | -## Issues and contacts |
| 85 | +- [Basic syntax](/languages/tolk/basic-syntax) |
| 86 | +- [Idioms and conventions](/languages/tolk/idioms-conventions) |
| 87 | +- [Type system](/languages/tolk/types/list-of-types) |
| 88 | +- [Message handling](/languages/tolk/features/message-handling) |
110 | 89 |
|
111 | | -If you encounter an issue, please connect with the developer community on [TON Dev chats](https://t.me/addlist/1r5Vcb8eljk5Yzcy) or create a [GitHub issue](https://github.com/ton-community/ton-docs/issues). |
| 90 | +## External resources |
112 | 91 |
|
113 | | -## See also |
| 92 | +Useful links outside this documentation: |
114 | 93 |
|
115 | | -- [Tolk vs FunC](/languages/tolk/from-func/tolk-vs-func) |
| 94 | +- [TON Dev chats](https://t.me/addlist/1r5Vcb8eljk5Yzcy) in Telegram |
| 95 | +- [@tolk\_lang channel](https://t.me/tolk_lang) in Telegram |
| 96 | +- [GitHub](https://github.com/ton-blockchain/ton) for issues and sources |
0 commit comments