Liteserver Node
Read about Full Node before this article
When an endpoint is activated in a full node, the node assumes the role of a Liteserver. This node type can field and respond to requests from Lite Clients, allowing for seamless interaction with the TON Blockchain.
Hardware requirements
Compared to a validator, a liteserver mode requires less resources. However, it is still recommended to use a powerful machine to run a liteserver.
- at least 16 cores CPU
- at least 128 GB RAM
- at least 1TB GB NVMe SSD OR Provisioned 32+k IOPS storage
- 1 Gbit/s network connectivity
- 16 TB/month traffic on peak load
- public IP address (fixed IP address)
Recommended Providers
Feel free to use cloud providers listed in the Recommended Providers section.
Hetzner and OVH are forbidden to run a validator, but you can use them to run a liteserver:
- Hetzner: EX101, AX102
- OVH: RISE-4
Installation of liteserver
If you don't have mytonctrl, install it with -m liteserver
flag:
- Ubuntu
- Debian
wget https://raw.githubusercontent.com/ton-blockchain/mytonctrl/mytonctrl2/scripts/install.sh
sudo bash install.sh -m liteserver -b mytonctrl2 -d
wget https://raw.githubusercontent.com/ton-blockchain/mytonctrl/mytonctrl2/scripts/install.sh
su root -c 'bash install.sh -m liteserver -b mytonctrl2 -d'
If you already have mytonctrl installed, run:
user@system:~# mytonctrl
MyTonCtrl> enable_mode liteserver
Check the firewall settings
First, verify the Liteserver port specified in your config.json
file. This port changes with each new installation of MyTonCtrl
. It is located in the port
field:
{
...
"liteservers": [
{
"ip": 1605600994,
"port": LITESERVER_PORT
...
}
]
}
If you are using a cloud provider, you need to open this port in the firewall settings. For example, if you are using AWS, you need to open the port in the security group.
Below is an example of opening a port in the bare metal server firewall.
Opening a port in the firewall
We will use the ufw
utility (cheatsheet). You can use the one you prefer.
- Install
ufw
if it is not installed:
sudo apt update
sudo apt install ufw
- Allow ssh connections:
sudo ufw allow ssh
- Allow the port specified in the
config.json
file:
sudo ufw allow <port>
- Enable the firewall:
sudo ufw enable
- Check the firewall status:
sudo ufw status
This way, you can open the port in the firewall settings of your server.
Interaction with Liteserver (Lightclient)
Create an empty project on your machine and paste
config.json
in the project directory.Install libraries.
- JavaScript
- Python
- Golang
npm i --save ton-core ton-lite-client
pip install pytonlib
go get github.com/xssnick/tonutils-go
go get github.com/xssnick/tonutils-go/liteclient
go get github.com/xssnick/tonutils-go/ton
- Initialize a client and request masterchain info to ensure the liteserver is running.
- JavaScript
- Python
- Golang
Change project type to module
in your package.json
file:
{
"type": "module"
}
Create index.js
file with the following content:
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()
from pytoniq import LiteClient
async def main():
client = LiteClient.from_mainnet_config( # choose mainnet, testnet or custom config dict
ls_i=0, # index of liteserver from config
trust_level=2, # trust level to liteserver
timeout=15 # timeout not includes key blocks synchronization as it works in pytonlib
)
await client.connect()
await client.get_masterchain_info()
await client.reconnect() # can reconnect to an exising object if had any errors
await client.close()
""" or use it with context manager: """
async with LiteClient.from_mainnet_config(ls_i=0, trust_level=2, timeout=15) as client:
await client.get_masterchain_info()
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.