Compile from Sources
You can download prebuilt binaries here.
If you still want to compile sources yourself, follow the instructions below.
This is a simplified quick build guide.
If you are building for production and not for home use, it's better to use autobuild scripts.
Common
The software is likely to compile and work properly on most Linux systems. It should work on macOS and even Windows.
- Download the newest version of TON Blockchain sources available at the GitHub repository https://github.com/ton-blockchain/ton/:
git clone --recurse-submodules https://github.com/ton-blockchain/ton.git
- Install the newest versions of:
make
cmake
version 3.0.2 or laterg++
orclang
(or another C++14-compatible compiler as appropriate for your operating system).- OpenSSL (including C header files) version 1.1.1 or later
build-essential
,zlib1g-dev
,gperf
,libreadline-dev
,ccache
,libmicrohttpd-dev
,pkg-config
,libsodium-dev
,libsecp256k1-dev
,liblz4-dev
On Ubuntu
apt update
sudo apt install build-essential cmake clang openssl libssl-dev zlib1g-dev gperf libreadline-dev ccache libmicrohttpd-dev pkg-config libsodium-dev libsecp256k1-dev liblz4-dev
- Suppose that you have fetched the source tree to directory
~/ton
, where~
is your home directory, and that you have created an empty directory~/ton-build
:
mkdir ton-build
Then run the following in a terminal of Linux or MacOS:
cd ton-build
export CC=clang
export CXX=clang++
cmake -DCMAKE_BUILD_TYPE=Release ../ton && cmake --build . -j$(nproc)
On MacOS
Prepare the system by installing required system packages
brew install ninja libsodium libmicrohttpd pkg-config automake libtool autoconf gnutls
brew install llvm@16
Use newly installed clang.
export CC=/opt/homebrew/opt/llvm@16/bin/clang
export CXX=/opt/homebrew/opt/llvm@16/bin/clang++
Compile secp256k1
git clone https://github.com/bitcoin-core/secp256k1.git
cd secp256k1
secp256k1Path=`pwd`
git checkout v0.3.2
./autogen.sh
./configure --enable-module-recovery --enable-static --disable-tests --disable-benchmark
make -j12
and lz4:
git clone https://github.com/lz4/lz4
cd lz4
lz4Path=`pwd`
git checkout v1.9.4
make -j12
and relink OpenSSL 3.0
brew unlink openssl@1.1
brew install openssl@3
brew unlink openssl@3 && brew link --overwrite openssl@3
Now you can compile TON
cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DSECP256K1_FOUND=1 \
-DSECP256K1_INCLUDE_DIR=$secp256k1Path/include \
-DSECP256K1_LIBRARY=$secp256k1Path/.libs/libsecp256k1.a \
-DLZ4_FOUND=1 \
-DLZ4_LIBRARIES=$lz4Path/lib/liblz4.a \
-DLZ4_INCLUDE_DIRS=$lz4Path/lib
:::
If you are compiling on a computer with low memory (e.g., 1 Gb), don't forget to create a swap partitions.
Download Global Config
For tools like lite client you need to download the global network config.
Download the newest configuration file from https://ton-blockchain.github.io/global.config.json for mainnet:
wget https://ton-blockchain.github.io/global.config.json
or from https://ton-blockchain.github.io/testnet-global.config.json for testnet:
wget https://ton-blockchain.github.io/testnet-global.config.json
Lite Client
To build a lite client, do common part, download the config, and then do:
cmake --build . --target lite-client
Run the Lite Client with config:
./lite-client/lite-client -C global.config.json
If everything was installed successfully, the Lite Client will connect to a special server (a full node for the TON Blockchain Network) and will send some queries to the server. If you indicate a writeable "database" directory as an extra argument to the client, it will download and save the block and the state corresponding to the newest masterchain block:
./lite-client/lite-client -C global.config.json -D ~/ton-db-dir
Basic help info can be obtained by typing help
into the Lite Client. Type quit
or press Ctrl-C
to exit.
FunC
To build FunC compiler from source code, do common part described above and then:
cmake --build . --target func
To compile FunC smart contract:
./crypto/func -o output.fif -SPA source0.fc source1.fc ...
Fift
To build Fift compiler from source code, do common part described above and then:
cmake --build . --target fift
To run Fift script:
./crypto/fift -s script.fif script_param0 script_param1 ..
Tonlib-cli
To build tonlib-cli, do common part, download the config and then do:
cmake --build . --target tonlib-cli
Run the tonlib-cli with config:
./tonlib/tonlib-cli -C global.config.json