Overview
A high-level language FunC is used to program smart contracts on TON.
FunC is a domain-specific, C-like, statically typed language. Here is a simple example method for sending money written in FunC:
() send_money(slice address, int amount) impure inline {
var msg = begin_cell()
.store_uint(0x10, 6) ;; nobounce
.store_slice(address)
.store_grams(amount)
.end_cell();
send_raw_message(msg, 64);
}
FunC programs are compiled into Fift assembler code, which generates corresponding bytecode for the TON Virtual Machine.
Further this bytecode (actually a tree of cells, like any other data in TON Blockchain) can be used for creating smart contracts in the blockchain or can be run on a local instance of TVM.
You can find more information about FunC in the DOCUMENTATION section.
FunC documentation was initially written by @akifoq.
Compiler
Compile with JS
Most convenient and quick way to begin develop and compile smart contracts is using Blueprint framework. Read more in Blueprint section.
npm create ton@latest
Compile with original binaries
If you want to use native TON compiler FunC locally you need binaries setup on your machine. FunC compiler binaries for Windows, MacOS (Intel/M1), and Ubuntu can be downloaded from:
At the same time you can always make binaries from sources like:
FunC compiler source code (read how to compile a FunC compiler from sources).
Tutorials
The best place to start to develop using FunC: INTRODUCTION
Other materials gracefully provided by the experts from the community:
- Func & BluePrint by @MarcoDaTr0p0je
- Learn FunC in Y Minutes by @romanovichim
- TON Hello World: Step-by-step guide for writing your first smart contract
- TON Hello World: Step by step guide for testing your first smart contract
- 10 FunC Lessons by @romanovichim, using toncli and toncli tests v1
- 10 FunC lessons by @romanovichim, using toncli and toncli tests v1 in Russian
- FunC Quiz by Vadim—Good for selfcheck. It will take 10–15 minutes. The questions are mainly about FunС with a few general questions about TON
- FunC Quiz by Vadim—FunC Quiz in Russian
Contests
Participating in contests is a great way to learn FunC.
You can also study previous competitions for learning purposes:
TON Smart Challenge #2 (good for getting started): Contest Page, Tasks, Solutions, Tests.
TON Smart Challenge #1 (good for beginners): Contest Page, Tasks, Solutions, Tests.
TON Smart Challenge #3 (intermediate): Contest Page, Tasks, Solutions.
Smart contract examples
Standard basic smart contracts like wallets, electors (manages validation on TON), multi-signature wallets, etc. can be a reference when studying.