Skip to main content

Compile from Sources

You can download prebuilt binaries here.

If you still want to compile sources yourself, follow the instructions below.

caution

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.

  1. 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
  1. Install the newest versions of:
    • make
    • cmake version 3.0.2 or later
    • g++ or clang (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

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
  1. 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 [email protected]
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

:::

tip

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:

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:

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

Basic help info can be obtained by typing help into the tonlib-cli. Type quit or press Ctrl-C to exit.

RLDP-HTTP-Proxy

To build rldp-http-proxy, do common part, download the config and then do:

cmake --build . --target rldp-http-proxy

The Proxy binary will be located as:

rldp-http-proxy/rldp-http-proxy

generate-random-id

To build generate-random-id, do common part and then do:

cmake --build . --target generate-random-id

The binary will be located as:

utils/generate-random-id

storage-daemon

To build storage-daemon and storage-daemon-cli, do common part and then do:

cmake --build . --target storage-daemon storage-daemon-cli

The binary will be located at:

storage/storage-daemon/

Compile old TON versions

TON releases: https://github.com/ton-blockchain/ton/tags

git clone https://github.com/ton-blockchain/ton.git
cd ton
# git checkout <TAG> for example checkout func-0.2.0
git checkout func-0.2.0
git submodule update --init --recursive
cd ..
mkdir ton-build
cd ton-build
cmake ../ton
# build func 0.2.0
cmake --build . --target func

Compile old versions on Apple M1:

TON supports Apple M1 from 11 Jun 2022 (Add apple m1 support (#401) commit).

To compile older TON revisions on Apple M1:

  1. Update RocksDb submodule to 6.27.3

    cd ton/third-party/rocksdb/
    git checkout fcf3d75f3f022a6a55ff1222d6b06f8518d38c7c
  2. Replace root CMakeLists.txt by https://github.com/ton-blockchain/ton/blob/c00302ced4bc4bf1ee0efd672e7c91e457652430/CMakeLists.txt