Giter Site home page Giter Site logo

evgeniyshvetcov / ton-client-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from radianceteam/everscale-client-dotnet

0.0 1.0 0.0 64.34 MB

TON SDK Client library binding for DotNet

License: Apache License 2.0

C# 94.79% TypeScript 5.21%

ton-client-dotnet's Introduction

TON SDK .NET Wrapper

Community links:

Chat on Telegram

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

Development

See Development documentation.

License

Apache License, Version 2.0.

Troubleshooting

Fire any question to our Telegram channel.

ton-client-dotnet's People

Contributors

andy-a-o avatar evgeniyshvetcov avatar samorodkin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.