LiteClient
LiteClient sends LiteAPI requests directly to TON liteservers over native
ADNL TCP. It is available with the liteclient feature, which also enables TL,
TVM, and ADNL TCP support. It supports typed request helpers and raw LiteAPI
bytes for methods that are not yet wrapped by a convenience method.
Audience: callers that already have a liteserver endpoint or TON global config.
Prerequisites: async Rust runtime, liteclient feature, and live network access.
For multi-peer retry behavior, see LiteBalancer. For shell
commands over the same APIs, see CLI.
Connect From Global Config
#![allow(unused)]
fn main() {
use std::str::FromStr;
use tonutils::liteclient::client::LiteClient;
use tonutils::network_config::ConfigGlobal;
async fn example(config_json: &str) -> anyhow::Result<()> {
let config = ConfigGlobal::from_str(config_json)?;
let mut client = LiteClient::connect_config(&config, 0).await?;
let info = client.get_masterchain_info().await?;
println!("{}", info.last.seqno);
Ok(())
}
}
Raw Query
Use query_raw when a LiteAPI constructor is known by schema but does not yet
have a typed Rust convenience method. The input must be an already serialized
LiteAPI request body. The output is the raw serialized LiteAPI response body.
#![allow(unused)]
fn main() {
use std::str::FromStr;
use tonutils::liteclient::client::LiteClient;
use tonutils::network_config::ConfigGlobal;
async fn example(config_json: &str, request: Vec<u8>) -> anyhow::Result<()> {
let config = ConfigGlobal::from_str(config_json)?;
let mut client = LiteClient::connect_config(&config, 0).await?;
let response = client.query_raw(request).await?;
println!("{}", hex::encode(response));
Ok(())
}
}
Request Rate Limits
LiteClient is unlimited by default. To stay within a provider quota, attach a
local token-bucket limiter before sending requests:
#![allow(unused)]
fn main() {
use tonutils::liteclient::{
client::LiteClient,
rate_limit::RequestRateLimit,
};
async fn example(mut client: LiteClient) -> anyhow::Result<()> {
client.set_rate_limit(RequestRateLimit::per_second(5)?);
let info = client.get_masterchain_info().await?;
println!("{}", info.last.seqno);
Ok(())
}
}
The limiter waits asynchronously instead of failing fast. Typed helpers and raw
queries share the same query_raw path, so one configured limit covers both.
Contract Helpers
tonutils::contracts::Contract reuses LiteClient::get_masterchain_info,
LiteClient::get_account_state, and LiteClient::run_get_method. It does not
change the LiteAPI trust model: proof fields are preserved, but proof
verification is not implemented yet.
Decoded BoC Helpers
tonutils::liteclient::boc contains offline decode helpers for LiteClient
payloads. Each helper preserves the raw BoC bytes and decoded root cell, then
adds a typed view where Phase 1 models exist:
decode_account_state_boc->Accountdecode_block_boc-> generated-backedBlockwrapperdecode_config_params_boc->ConfigParamsdecode_shard_state_boc->ShardStatedecode_merkle_proof_bocanddecode_merkle_update_boc-> exotic proof primitive wrappers
These helpers intentionally do not verify liteserver proofs by default. The
Merkle wrappers expose verify_virtual_hash and verify_virtual_hashes for
the local exotic-cell child-hash invariant only; callers must still anchor
proofs to trusted block ids before using decoded data as trusted state.
#![allow(unused)]
fn main() {
use tonutils::liteclient::boc::decode_account_state_boc;
fn example(raw_state_boc: &[u8]) -> anyhow::Result<()> {
let decoded = decode_account_state_boc(raw_state_boc)?;
println!("{}", decoded.boc.root_hash_hex());
println!("{:?}", decoded.account);
Ok(())
}
}
Typed Phase 1 Additions
Recent typed helpers added to LiteClient:
raw_get_blockandraw_get_block_dataraw_get_block_headerget_account_state_typed,raw_get_account_state, andget_account_state_simpleraw_get_shard_infoandraw_get_all_shards_infoget_one_transaction_typed,raw_get_transactions, andraw_get_block_transactions_extrun_get_method_typedget_config_all_typedandget_config_params_typedget_libraries_typedandget_libraries_with_proof_typedlookup_block_with_prooflist_block_transactions_extget_libraries_with_proofget_shard_block_proofget_out_msg_queue_sizesget_block_out_msg_queue_sizeget_dispatch_queue_infoget_dispatch_queue_messagesget_nonfinal_validator_groupsget_nonfinal_candidateget_nonfinal_pending_shard_blocks
Example:
#![allow(unused)]
fn main() {
use tonutils::liteclient::client::LiteClient;
use tonutils::tl::{BlockId, BlockIdExt};
async fn example(client: &mut LiteClient, block_id: BlockId, mc_block_id: BlockIdExt) -> anyhow::Result<()> {
let proof = client
.lookup_block_with_proof((), block_id, mc_block_id, None, None)
.await?;
println!("{}", proof.id.seqno);
Ok(())
}
}
Current Limits
The client has typed helpers for the common LiteAPI surface and a raw byte
escape hatch for missing constructors, including typed BoC decode wrappers for
block, account, transaction, shard, config, library, and get-method result
payloads. Full trust-level proof verification and full block.tlb expansion
are not implemented. Timeout configuration is currently limited, and
live-network behavior depends on the selected liteserver.
Nonfinal Typed Calls
Nonfinal constructors expose candidate and validator-group data that may change before finalization. They are useful for diagnostics and research flows and do not include proof verification or production-safety guarantees.
#![allow(unused)]
fn main() {
use tonutils::liteclient::client::LiteClient;
use tonutils::tl::NonfinalCandidateId;
async fn example(client: &mut LiteClient, candidate_id: NonfinalCandidateId) -> anyhow::Result<()> {
let groups = client.get_nonfinal_validator_groups(None).await?;
println!("{}", groups.groups.len());
let candidate = client.get_nonfinal_candidate(candidate_id).await?;
println!("{}", candidate.data.len());
Ok(())
}
}
Shell Equivalent
tonutils --output json liteclient masterchain-info --ls-index 0
tonutils --rps 5 --output json liteclient masterchain-info --ls-index 0
tonutils --output hex liteclient raw-query --ls-index 0 --hex '<serialized-request-hex>'
tonutils --output json contract run-get-method --address '<addr>' --method seqno