An open API service indexing awesome lists of open source software.

https://github.com/radianceteam/everscale-client-dotnet

Everscale SDK Client library binding for .NET
https://github.com/radianceteam/everscale-client-dotnet

blockchain dotnet everscale everscale-sdk freeton freeton-sdk ton ton-client

Last synced: 5 months ago
JSON representation

Everscale SDK Client library binding for .NET

Awesome Lists containing this project

README

          

# TON SDK .NET Wrapper

**Community links:**

[![Chat on Telegram](https://img.shields.io/badge/chat-on%20telegram-9cf.svg)](https://t.me/RADIANCE_TON_SDK)

## 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

```cs
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

```cs
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()`:

```cs
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:

```cs
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:

```cs
using var client = TonClient.Create(new ClientConfig {
// ...
}, new MyLogger()));
```

Note: see [TonClientDemo](src/TonClientDemo) for the complete working demo.

#### Passing JToken values

Some API methods require `JToken` parameters. [JToken](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm)
is a class from [Newtonsoft.Json](https://www.nuget.org/packages/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:

```cs

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](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm) from .NET object of anonymous type.

## More Examples

See [Examples](examples) directory.

## Development

See [Development documentation](development.md).

## License

Apache License, Version 2.0.

## Troubleshooting

Fire any question to our [Telegram channel](https://t.me/RADIANCE_TON_SDK).