Ditch

Library for interaction with graphene-based blockchains.


Overview

Ditch is a safe, fast, simple and downright gorgeous library written in C# using .NET standard 2.0

Safe

The library independently signs transactions, therefore the user's private key is never transferred to third-party resources.

Fast

For signing transaction used the most performance realization of ECDSA Secp256k1.

Simple

Library already know how to generates, signs and sends transaction to blockchain. You need only set you data.

Work anywhere

.NET standard allows easily attach library to Android, iOS and windows applications.

Free

The library distributed under the MIT license.


Installation

Install with a Package Manager

To work with Steem steem blockchain, install Ditch.Steem:

PM> Install-Package Ditch.Steem

To work with Golos golos blockchain, install Ditch.Golos:

PM> Install-Package Ditch.Golos

Installation from source code

Ditch is open source library. You may download the latest version from github.

Open Ditch.sln in Visual Studio 2017 and build it

or

open Automation directory and run build_solution.cmd

or

open cmd and type dotnet build *path to Ditch*\Sources\Ditch.sln

Note:

When the installation is performed through the Package Manager, then all dependent libraries will be loaded automatically.

When the installation is performed from the source code - you need to add all references manually!

Getting Started

All work is managed by OperationManager. It is necessary to add it to the code and initialize.

Initializing

private readonly OperationManager _operationManager;

public void InitializeOperationManager
{
    //specify how to parse json
    var jss = new JsonSerializerSettings
    {
        DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK",
        Culture = CultureInfo.InvariantCulture
    };

    //specify how to connect to blockchain
    var cm = new WebSocketManager(jss);
    _operationManager = new OperationManager(cm, jss);
}   

Note:

Different blockhouses may require different ways to connect (http/https or ws/wss)

Chose HttpManager for https connections or WebSocketManager for wss connections.

Connection to blockchain

Before sending / receiving messages it is also necessary to establish a network connection:

public void ConnectToNode()
{
    var cUrls = new List<string> { "wss://ws.golos.io" };
    var conectedTo = _operationManager.TryConnectTo(cUrls, CancellationToken.None);
}

You may specify several endpoints. OperationManager sequentially get endpoint from the list, connect to the node and download the node parameters witch necessary for further work.

conectedTo returns the endpoint to which the OperationManager was connected or null in case there is no connection.

Execute get request

To get data from the blockchain, you may use ready-made api methods like:

// get node configuration
var dynamicGlobalProperties = _operationManager.GetDynamicGlobalProperties(CancellationToken.None);
// get hardfork version
var hardforkVersion = _operationManager.GetHardforkVersion(CancellationToken.None);

or you also may execute custom request like:

// get node configuration
var dynamicGlobalProperties = _operationManager.CallRequest<object>(KnownApiNames.DatabaseApi, "get_dynamic_global_properties", new object[] { }, CancellationToken.None);
// get hardfork version
var someClass = _operationManager.CallRequest<SomeClass>("Some blockshain api name", "some blockshain api method name", new object[] { *some input parameters* }, CancellationToken.None);

Execute post request

To write some data to the blockchain you also may use ready-made api methods like:

//operation vote up
var operation = new VoteOperation("YouLogin", "some author", "some authors post permlink", 10000);
var responce = _operationManager.BroadcastOperations(new byte[] { Base58.TryGetBytes("you private posting key")}, ct, operation);
// operations create new post with beneficiaries
var postOperation = new PostOperation("some category", "YouLogin", "post title", "post body", "some metadata");
var beneficiariesOperation = new BeneficiariesOperation("YouLogin", postOperation.Permlink, _operationManager.SbdSymbol, new Beneficiary("KorzunAV", 500));
var responce = _operationManager.BroadcastOperations(new byte[] { Base58.TryGetBytes("you private posting key")}, ct, postOperation, beneficiariesOperation);

or you also may execute custom request like:

// operation follow
var operation = new FollowOperation("YouLogin", "KorzunAV", FollowType.Blog, "YouLogin");
var prop = _operationManager.GetDynamicGlobalProperties(CancellationToken.None);
var transaction = _operationManager.CreateTransaction(prop.Result, new byte[] { Base58.TryGetBytes("you private posting key")}, CancellationToken.None, operation);
var resp = _operationManager.BroadcastTransaction(transaction, CancellationToken.None);
// operation follow
var operation = new SomeCustomOperationInheritBaseOperation(*some parameters*);
var prop = _operationManager.GetDynamicGlobalProperties(CancellationToken.None);
var transaction = _operationManager.CreateTransaction(prop.Result, new byte[] { Base58.TryGetBytes("you private posting key")}, CancellationToken.None, operation);
var resp = _operationManager.BroadcastTransaction(transaction, CancellationToken.None);

Supported blockchains

golos steem Created with Sketch.

Our Plans

BitShares Created with Sketch.

Getting help

To get help with Ditch, please use the Telegram or GitHab issues.