Running a Liteserver
To install and manage your own liteserver, use the mytonctrl open source tool developed by TON Foundation.
Hardware requirements
- at least 8 cores CPU
- at least 8 GB RAM
- at least 512 GB NVMe SSD
- 1 Gbit/s network connectivity
- public IP address (fixed IP address)
Installation
mytonctrl installation
- Download the installation script.
wget https://raw.githubusercontent.com/ton-blockchain/mytonctrl/master/scripts/install.sh
- Run the installation script with the next flags:
-m full
- Full node installation.-d
- mytonctrl will download a dump of the latest blockchain state. This will reduce liteserver synchronization time by several times.-c <path>
- If you want to use not public liteservers for synchronization.
- Ubuntu
- Debian
sudo bash install.sh -m full -d
su root -c 'bash install.sh -m full -d'
- After installation run mytonctrl CLI and check its status:
$ mytonctrl
MyTonCtrl> status
Wait until Local validator out of sync
become less than 20 seconds.
Liteserver config
- Create config file
MyTonCtrl> installer
MyTonInstaller> clcf
Local config file created: /usr/bin/ton/local.config.json
- Copy the config file located on the specified path. You will need this file to connect to your liteserver.
Interaction with Liteserver
- Install libraries.
- Python
- JavaScript
- Golang
pip install pytonlib
npm i --save ton-core ton-lite-client
go get github.com/xssnick/tonutils-go
go get github.com/xssnick/tonutils-go/liteclient
go get github.com/xssnick/tonutils-go/ton
- Initialize client and request masterchain info to make sure liteserver is running.
- Python
- JavaScript
- Golang
import asyncio
from pytonlib import TonlibClient
from pathlib import Path
import json
async def get_client() -> TonlibClient:
with open('config.json', 'r') as f:
config = json.loads(f.read())
keystore_dir = '/tmp/ton_keystore'
Path(keystore_dir).mkdir(parents=True, exist_ok=True)
client = TonlibClient(ls_index=0, config=config, keystore=keystore_dir, tonlib_timeout=10)
await client.init()
return client
async def test_client():
client = await get_client()
print(await client.get_masterchain_info())
await client.close()
if __name__ == '__main__':
asyncio.run(test_client())
import { LiteSingleEngine } from 'ton-lite-client/dist/engines/single.js'
import { LiteRoundRobinEngine } from 'ton-lite-client/dist/engines/roundRobin.js'
import { LiteClient } from 'ton-lite-client/dist/client.js'
import config from './config.json' assert {type: 'json'};
function intToIP(int ) {
var part1 = int & 255;
var part2 = ((int >> 8) & 255);
var part3 = ((int >> 16) & 255);
var part4 = ((int >> 24) & 255);
return part4 + "." + part3 + "." + part2 + "." + part1;
}
let server = config.liteservers[0];
async function main() {
const engines = [];
engines.push(new LiteSingleEngine({
host: `tcp://${intToIP(server.ip)}:${server.port}`,
publicKey: Buffer.from(server.id.key, 'base64'),
}));
const engine = new LiteRoundRobinEngine(engines);
const client = new LiteClient({ engine });
const master = await client.getMasterchainInfo()
console.log('master', master)
}
main()
package main
import (
"context"
"encoding/json"
"io/ioutil"
"log"
"github.com/xssnick/tonutils-go/liteclient"
"github.com/xssnick/tonutils-go/ton"
)
func main() {
client := liteclient.NewConnectionPool()
content, err := ioutil.ReadFile("./config.json")
if err != nil {
log.Fatal("Error when opening file: ", err)
}
config := liteclient.GlobalConfig{}
err = json.Unmarshal(content, &config)
if err != nil {
log.Fatal("Error during Unmarshal(): ", err)
}
err = client.AddConnectionsFromConfig(context.Background(), &config)
if err != nil {
log.Fatalln("connection err: ", err.Error())
return
}
// initialize ton api lite connection wrapper
api := ton.NewAPIClient(client)
master, err := api.GetMasterchainInfo(context.Background())
if err != nil {
log.Fatalln("get masterchain info err: ", err.Error())
return
}
log.Println(master)
}
- Now you can interact with your own liteserver.