Published 7 December 2018

Using of Credits API in C # (demo).



How to connect to a node to call the Credits API

How to connect to a node to call the Credits API

To call the Credits API you have to connect to the Node’s Thrift API via port 9090. This port must be added to the firewall exceptions if you intend to connect to the Node’s Thrift API from the network.

Also, a prerequisite for the correct use of the Node’s Thrift API is that the node must be fully synchronized.

The three main components you need to use with the API are:

Apache Thrift library (  

ABase58 encoding/decoding library for encoding and decoding pub and priv keys

Elliptic-curve digital signature library

Before generating code you have to do the following:

Download Credits API files

Download Apache Thrift itself:

After creating the project you have to execute

The code generation command: thrift --gen csharp api.thrift

Files will be generated in gen-csharp directory, copy and paste files into your project.

Apache Thrift, (Install from Nuget - ApacheThrift)

A C# package called Simplebase to handle the encoding/decoding (, (Install from Nuget - SimpleBase)

Chaos.NaCI to handle the elliptic-curve digital signature algorithm Ed25519 (, (Install from Nuget - dlech.Chaos.NaCl)

In this demo, wallet balance calls are implemented:

#region GetBalance

//Get the balance of our wallet.

var balance = client.BalanceGet(publicKeyBytes, 0);

Console.WriteLine($"[{publicKey}] Balance: {balance.Amount} CS");

Console.WriteLine($"[{publicKey}] Balance: {ConvUtils.FormatAmount(balance.Amount)} CS");


create and execute a transaction:

#region CreateTransaction

//Create a transaction

var transaction = new Transaction();

transaction.Id = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();

transaction.Source = publicKeyBytes;

transaction.Target = targetPublicKeyBytes;

transaction.Amount = new Amount(5, 0);

transaction.Balance = balance.Amount;

transaction.Fee = new Amount(0, 0);

transaction.Currency = 1;

//Create the signature of the transaction by writing the values into a memory stream and then writes the contents out into a bytearray.

byte[] bytes;

using (var memoryStream = new MemoryStream())


   using (BinaryWriter writer = new BinaryWriter(memoryStream))












      bytes = memoryStream.ToArray();


var lastHash = SimpleBase.Base58.Bitcoin.Encode(client.GetLastHash());

//Sign the bytearray with the privateKey

var signature = Ed25519.Sign(bytes, privateKeyBytes);

//Verify the signature is correct.

var verifyResult = Ed25519.Verify(signature, bytes, SimpleBase.Base58.Bitcoin.Decode(publicKey).ToArray());

if (!verifyResult) throw new Exception("Signature could not be verified");

transaction.Signature = signature;

var transactionResult = client.TransactionFlow(transaction);



Check the performance. Call the GetBalance Method.

As the result of the program we see the requested balance:


14 Useful article