Hive libraries for Microsoft .NET now fully support broadcasting transactions

Months ago, I introduced the Hive library for Microsoft .NET developers. This library provides developers used to VB.NET and C# languages with easy-to-use .NET classes, exposing almost all the APIs of the hived and cli_wallet daemons.

It's also available as a "COM library" (aka .dll) so people can use it directly in their favorites COM-enabled Windows applications like Word, Excel, ...

A missing feature

Although the existing library was versatile enough to read information from the blockchain and even record transactions in it, it was however limited to operations that can be sent to the blockchain through the interfaces exposed by the cli_wallet.

Although most of the usual operations are available through that interface, many new operations have been supported by the blockchain but not added to the cli_wallet API (yet).

On the other hand, this way of sending transactions to the blockchain requires that you have a running daemon available at hand, and in case of failure you cannot easily switch to another.

I had wanted for years to have the ability to connect my library directly to API servers that several Witnesses operate (including myself), but so far I have managed to postpone this work. Time to cut it out!

Taking matters into my own hands

Broadcasting transactions directly to the blockchain means serializing the transaction and signing it before sending it to an RPC node.

Easier said than done because it is an area that was new to me and I know several who have broken their teeth there. Never mind, I like to take up challenges and I often tell myself that nothing is impossible when approached with calm and patience.

Thanks to the Hive developers portal tutorial about transactions, I gradually integrated the understanding of the serialization and cryptography processes required to sign transactions.

As a result, it is no longer necessary to go through cli_wallet to write operations into the blockchain, and all available operations can now be broadcasted using the hive.net library.

Code example

The library is really easy to use. Here is a simple C# code example that broadcast a vote operation to the blockchain:

string strPosting = "5...";   // Posting private key
string strActive = "5...";    // Active private key

HttpClient oHTTP = new HttpClient();
CHived oHived = new CHived(oHTTP, "https://api.hive.blog");

COperations.vote oVote = new COperations.vote {
    voter = "arcange", 
    author = "author", 
    permlink = "permlink",
    weight = 100 
    };

try 
{

    string txid = oHived.broadcast_transaction(
        new object[] { oVote }, 
        new string[] { strPosting }
        );

    Console.Write(txid);
}
catch (Exception e)
{
    Console.Write(e.Message);
}

Broadcasting multiple operations at once with a single transaction is also very easy:

COperations.transfer oTransfer1 = new COperations.transfer { 
    from = "arcange", 
    to = "account1", 
    amount = new Asset("0.001 HIVE"), 
    memo = "A first transfer" 
    };
    
COperations.transfer oTransfer2 = new COperations.transfer { 
    from = "arcange", 
    to = "account2", 
    amount = new Asset("1.000 HBD"), 
    memo = "A second transfer" 
    };
    
try
{
    string txid = oHived.broadcast_transaction(
        new object[] { oTransfer1, oTransfer2 }, 
        new string[] { strActive }
        );
    Console.Write(txid);
}
catch (Exception e)
{
    Console.Write(e.Message);
}

Here is another example in VB.NET:

Dim strActive = "5...."    ' Posting private key
Dim strPosting = "5...."   ' Active Private key

Dim oHttp As HttpClient = New HttpClient()
Dim oHiveAPI = New CHived(oHttp, "https://api.hive.blog")

Dim oWitnessUpdate As New COperations.witness_update With {
    .owner = "arcange",
    .url = "https://....",
    .block_signing_key = New PublicKey("STM...."),
    .props = New ChainProperties With {
        .account_creation_fee = New Asset(3, "HIVE"),
        .maximum_block_size = 65536,
        .hbd_interest_rate = 1000
        },
    .fee = New Asset(3, "HIVE")
    }

Try
    Dim txid = oHiveAPI.broadcast_transaction({oWitnessUpdate}, {strPosting})
    Console.Write(txid)
Catch ex As Exception
    Console.Write(ex.Message)
End Try

What's next?

There is still some work to do:

  • add a set of functions to simplify the generation of the most used operations.
  • create documentation
  • create some tutorials

I plan to tackle these tasks in the next weeks.

Open source

The libraries are open source and can be found on GitLab.

If you have any comments or requests, please create an issue on GitLab too. You can also contact me on Discord or Telegram


Check out my apps and services


Vote for me as a witness

H2
H3
H4
3 columns
2 columns
1 column
19 Comments
Ecency