TonLib.Net 0.3.0

.NET 6.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package TonLib.Net --version 0.3.0
NuGet\Install-Package TonLib.Net -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TonLib.Net" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TonLib.Net --version 0.3.0
#r "nuget: TonLib.Net, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TonLib.Net as a Cake Addin
#addin nuget:?package=TonLib.Net&version=0.3.0

// Install TonLib.Net as a Cake Tool
#tool nuget:?package=TonLib.Net&version=0.3.0


Wrapper around libtonlibjson library for accessing Telegram Open Network lite servers (nodes) via ADNL protocol.

Important! You need to obtain compiled tonlibjson.dll (or appropriate for your OS) and its dependencies (e.g. libcrypto-1_1-x64.dll) yourself. See below for details.


⚠ Uses System.Text.Json package v7.0.1 (from net7.0) - it makes [de]serialization much simpler (because of Polymorphic serialization). It only updates System.text.Encodings.Web (v6.0 → v7.0) as a transitive dependency, which I think is acceptable.


Register in Startup (for console projects - create instance manually or see demo project for hosted sample):

services.AddSingleton<ITonClient, TonClient>();

And use:

// Obtain client from DI
var tonClient = app.Services.GetRequiredService<ITonClient>();

// You need to init it before first use.
// During this, TON network config file is loaded from internet.
// Subsequent calls to `InitIfNeeded` will be ignored, 
//   so no need for you to have additional variable 
//   to remember that you already called it.
await tonClient.InitIfNeeded();

// Use 'Execute' to send requests.
var lsi = await tonClient.Execute(new LiteServerGetInfo());
logger.LogInformation("Server time: {Now}", lsi.Now);

var mi = await tonClient.Execute(new GetMasterchainInfo());
logger.LogInformation("Last block: shard = {Shard}, seqno = {Seqno}", mi.Last.Shard, mi.Last.Seqno);

And the result is:


Execute requests are not truly asynchronous now - calls to tonlib are synchronous, and only waiting between them is a reason for 'async'. Help is wanted to make Execute really asynchronous.

Installing dependencies and running a demo

This library is a wrapper around tonlibjson library. You need to obtain complied copy of it (and its dependencies) yourself.

1. Obtaining tonlibjson library

Option 1: Build it yourself
  1. Checkout
  2. Follow manual at and build tonlib target.
Option 2: Get compiled one from GitHub Actions
  1. Open
  2. Choose your OS (one that matches better) in left "Actions" (Workflows) menu
  3. Look for run with tag named like v2023.01 (or newer) and open that build/run.
  4. Scroll down to "Artifacts" section, you'll find something like ton-win-binaries file about 70MB in size. Download it.
  5. Open downloaded archive and extract tonlibjson.dll (or similair for your OS).
  6. Make sure this file will be available for your running program (for example, add it to your project and set "Copy to Output Directory" to "Copy if newer").

2. Obtaining dependencies

The number of additional dependencies you need depends of what you already have on your machine.

When something is missed, Demo app will fail with "Unable to load DLL 'tonlibjson' or one of its dependencies" exception. You may use Process Monitor to find what file it wants.

On my Win machine I needed libcrypto-1_1-x64.dll from OpenSSL.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.20.0-rc1 85 8/14/2023
0.19.0 2,179 7/8/2023
0.18.1 904 6/6/2023
0.17.1 160 6/5/2023
0.17.0 188 6/1/2023
0.16.0 431 5/18/2023
0.15.0 473 5/3/2023
0.14.1 233 4/27/2023
0.14.0 272 4/21/2023
0.13.0 241 4/16/2023
0.12.0 146 4/7/2023
0.11.0 174 3/26/2023
0.10.0 182 3/15/2023
0.9.0 167 3/9/2023
0.8.0 163 3/7/2023
0.7.0 182 3/5/2023
0.6.0 224 2/21/2023
0.5.0 200 2/21/2023
0.4.0 188 2/13/2023
0.3.1 207 2/6/2023
0.3.0 214 2/6/2023
0.2.0 233 2/1/2023
0.1.0 238 1/31/2023