Hive libraries for Microsoft .NET now fully support broadcasting transactions

in HiveDevs2 months ago

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

Sort:  

Nice reading this line:

...I often tell myself that nothing is impossible when approached with calm and patience.

This sentence your motto you can make, young padawan...

Great work @arcange, more and more easy-to-use libraries is what developers need!

Thanks mate. Yeah, I truly believe that it's by having more developers and apps built on top of the blockchain that Hive will succeed.



The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.

Your content has been voted as a part of Encouragement program. Keep up the good work!

Use Ecency daily to boost your growth on platform!

Support Ecency
Vote for Proposal
Delegate HP and earn more

Nicely done! Found this so helpful!

Very good work you 👏 did. Keep it up.

Very good work you 😍😍😍did. Keep it up.

Well, that's one I will definitly check out!
Thanks a lot👍

Is this the only C# library on Hive? Would like to see what kind of apps and games can be built with Hive and the Unity game engine.

AFAIK yes, that's the only maintained .NET library for Hive.

Congratulations @arcange! Your post has been a top performer on the Hive blockchain and you have been rewarded with the following badge:

Post with the highest payout of the day.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Day - August 1st 2021 - Hive Power Delegation