Community links:
- Windows x86, x64
- Linux x64
- macOS x64
- .NET Core 2.0 and newer.
- .NET Framework 4.6.1 and newer.
Install-Package TonClient
using TonSdk.Modules;
using (var client = TonClient.Create()) {
var version = await client.Client.VersionAsync();
Console.WriteLine($"TON SDK client version: {version.Version}");
}
using (var client = TonClient.Create(new ClientConfig
{
Network = new NetworkConfig
{
ServerAddress = "http://localhost",
MessageRetriesCount = 10,
OutOfSyncThreshold = 2500
},
Abi = new AbiConfig
{
MessageExpirationTimeout = 10000
}
}))
{
// ...
}
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.
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 Newtonsoft.Json.Linq;
using TonSdk.Modules;
using (var client = TonClient.Create()) {
var result = await client.Net.WaitForCollectionAsync(new ParamsOfWaitForCollection
{
Collection = "accounts",
Filter = JObject.FromObject(new
{
id = new { eq = "... some address" }
}),
Result = "id boc"
});
}
Note JObject.FromObject static method used for constructing JObject (which is a descendant of JToken type) from .NET object of anonymous type.
See Development documentation.
Apache License, Version 2.0.
Fire any question to our Telegram channel.