TON SDK .NET Wrapper
Community links:
Supported Platforms
- Windows x86, x64
- Linux x64
- macOS x64
Supported runtimes
- .NET Core 2.0 and newer.
- .NET Framework 4.6.1 and newer.
Installation
NuGet package
Install-Package TonClient
Usage examples
Basic usage
using TonSdk.Modules;
using var client = TonClient.Create();
var version = await client.Client.VersionAsync();
Console.WriteLine($"TON SDK client version: {version.Version}");
Advanced usage
Configuring client
using var client = TonClient.Create(new ClientConfig
{
Network = new NetworkConfig
{
ServerAddress = "http://localhost",
MessageRetriesCount = 10,
OutOfSyncThreshold = 2500
},
Abi = new AbiConfig
{
MessageExpirationTimeout = 10000
}
});
Logging
By default, wrapper uses DummyLogger
which is an implementation of ILogger
interface.
To configure custom logging, create own ILogger
implementation and pass it to TonClient.Create()
:
using System;
using Serilog;
using ILogger = TonSdk.ILogger;
...
public class MyLogger : ILogger
{
public void Debug(string message)
{
Log.Debug(message);
}
public void Information(string message)
{
Log.Information(message);
}
public void Warning(string message)
{
Log.Warning(message);
}
public void Error(string message, Exception ex = null)
{
Log.Error(ex, message);
}
}
then call TonClient.Create
method with logger argument:
using System;
using Serilog;
using TonSdk.Modules;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
// ... other logging setup
.CreateLogger();
using var client = TonClient.Create(new MyLogger());
or with both config and logger:
using var client = TonClient.Create(new ClientConfig {
// ...
}, new MyLogger()));
Note: see TonClientDemo for the complete working demo.
Passing JToken values
Some API methods require JToken
parameters. JToken
is a class from Newtonsoft.Json library used for JSON processing.
TON SDK .NET Wrapper library uses it for passing raw JSON data to the client library and back.
Here's the example of how to deal with it:
using TonSdk.Modules;
using var client = TonClient.Create();
var result = await client.Net.WaitForCollectionAsync(new ParamsOfWaitForCollection
{
Collection = "accounts",
Filter = new
{
id = new { eq = "... some address" }
}.ToJson(),
Result = "id boc"
});
Note ToJson
extension method used for constructing JToken from .NET object of anonymous type.
More Examples
See Examples directory.
Development
See Development documentation.
License
Apache License, Version 2.0.
Troubleshooting
Fire any question to our Telegram channel.