Skip to content

Commit e1f7951

Browse files
committed
[Tolk] New docs: overview page (landing)
1 parent c53fced commit e1f7951

File tree

3 files changed

+69
-88
lines changed

3 files changed

+69
-88
lines changed

contract-dev/first-smart-contract.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ First, we need a way to store the counter value. Tolk makes this simple with <To
118118

119119
```tolk title="./contracts/first_contract.tolk"
120120
struct Storage {
121-
counter: uint64; // the current counter value
121+
counter: uint64 // the current counter value
122122
}
123123
124124
// load contract data from persistent storage
@@ -153,17 +153,17 @@ Tolk structures are also useful for defining message bodies. In our case, we’l
153153
Each structure has a unique prefix (`0x7e8764ef` and `0x3a752f06`), widely called opcodes, that lets the contract distinguish between them.
154154

155155
```tolk title="./contracts/first_contract.tolk"
156-
struct(0x7e8764ef) IncreaseCounter {
156+
struct (0x7e8764ef) IncreaseCounter {
157157
increaseBy: uint32
158158
}
159159
160-
struct(0x3a752f06) ResetCounter {}
160+
struct (0x3a752f06) ResetCounter {}
161161
```
162162

163163
To group them together, we'll use a union. Unions allow multiple types to be bundled into a single type that can be serialized and deserialized automatically:
164164

165165
```tolk title="./contracts/first_contract.tolk"
166-
type AllowedMessage = IncreaseCounter | ResetCounter;
166+
type AllowedMessage = IncreaseCounter | ResetCounter
167167
```
168168

169169
Now we can write our message handler:
@@ -227,7 +227,7 @@ Here’s the full source code of `contracts/first_contract.tolk`:
227227

228228
```tolk title="./contracts/first_contract.tolk" expandable
229229
struct Storage {
230-
counter: uint64;
230+
counter: uint64
231231
}
232232
233233
fun Storage.load() {
@@ -238,13 +238,13 @@ fun Storage.save(self) {
238238
contract.setData(self.toCell());
239239
}
240240
241-
struct(0x7e8764ef) IncreaseCounter {
241+
struct (0x7e8764ef) IncreaseCounter {
242242
increaseBy: uint32
243243
}
244244
245-
struct(0x3a752f06) ResetCounter {}
245+
struct (0x3a752f06) ResetCounter {}
246246
247-
type AllowedMessage = IncreaseCounter | ResetCounter;
247+
type AllowedMessage = IncreaseCounter | ResetCounter
248248
249249
fun onInternalMessage(in: InMessage) {
250250
val msg = lazy AllowedMessage.fromSlice(in.body);

languages/func/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ noindex: "true"
77
import { Aside } from '/snippets/aside.jsx';
88

99
<Aside>
10-
TON Blockchain uses Tolk as the official language. Other languages are still available, and legacy codebases exist, but Tolk is the only actively supported language. The FunC compiler, for instance, is no longer maintained.
10+
TON Blockchain uses [Tolk](/languages/tolk) as the official language. Other languages are still available, and legacy codebases exist, but Tolk is the only actively supported language. The FunC compiler, for instance, is no longer maintained.
1111
</Aside>
1212

1313
FunC is a domain-specific, statically typed language with C-like syntax designed to write smart contracts on TON. It can be characterized as an intermediate-level language sitting on top of the [Fift](/languages/fift) assembly language.

languages/tolk/overview.mdx

Lines changed: 60 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,96 @@
11
---
2-
title: "Tolk"
2+
title: "Tolk — the language for TON"
33
sidebarTitle: "Overview"
44
---
55

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';
77

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.
99

10-
## Why choose Tolk
10+
It provides declarative structures, automatic cell serialization, first-class message handling, and a modern development experience.
1111

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.
3613

3714
```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
4716
4817
fun onInternalMessage(in: InMessage) {
49-
// ...
18+
val msg = lazy AllowedMessage.fromSlice(in.body);
19+
match (msg) {
20+
CounterIncrement => { ... }
21+
CounterReset => { ... }
22+
}
5023
}
5124
52-
get fun currentCounter(): int {
25+
get fun currentCounter() {
5326
val storage = lazy Storage.load();
5427
return storage.counter;
5528
}
5629
```
5730

58-
<details>
59-
<summary><b>Equivalent implementation in FunC</b></summary>
31+
## Key features
6032

61-
```func
62-
#include "utils.fc";
33+
Tolk offers high-level readability while remaining low-level in nature:
6334

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
6540

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>
7044

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:
7958

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+
```
8662

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".
8864

89-
## Tooling around Tolk
65+
1. Follow the ["Your first smart contract"](/contract-dev/first-smart-contract) article
66+
to get explanations.
9067

91-
A set of tools is available to support development with Tolk — including IDE support, language services, and migration utilities.
68+
## IDE support
9269

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:
9871

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
10074

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
10277

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
10480

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
10682

107-
Regardless of the language, well-tested code is the key to building reliable smart contracts.
83+
Recommended starting points:
10884

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)
11089

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
11291

113-
## See also
92+
Useful links outside this documentation:
11493

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

Comments
 (0)