justdmitry / TonLib.NET

tonlibjson wrapper for .NET
MIT License
10 stars 6 forks source link
the-open-network ton tonlib tonlibjson

TonLib.NET

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

Does not require TonAPI, TonCenter API, TonKeeper API or any other HTTP API.

NuGet NuGet downloads Framework Framework Framework GitHub License

⚠ For net6.0 uses System.Text.Json package v7.0.0 (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.

Features

And more:

Usage

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);

Run Demo project for more samples.

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.

Go to https://github.com/ton-blockchain/ton/releases, open latest release, scroll to "Assets" and download tonlibjson.* for your OS. 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").

The number of additional dependencies you need depends of what you already have on your machine. On my Win machine I also needed libcrypto-1_1-x64.dll from OpenSSL v1.1. You may use Process Monitor to find what it wants if it fails to run.

3rd-party libraries and dependencies

Donate

just_dmitry.ton

Useful links