Hive libraries for Microsoft .NET now fully support broadcasting transactions
![](https://i.imgur.com/uBDjiIT.png)
Months ago, I introduced the [Hive library for Microsoft .NET developers](/hive-139531/@arcange/msnet-libraries). 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](https://developers.hive.io/tutorials-recipes/how-to-serialize-and-sign-using-js.html), 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](https://gitlab.syncad.com/hive/hive-net).
If you have any comments or requests, please create an issue on GitLab too. You can also contact me on [Discord](https://discordapp.com/channels/@me/237480770933882881) or [Telegram](https://t.me/the_arcange)
---
### Check out my apps and services
### [Vote for me as a witness ![](https://i.imgur.com/2bi4SnT.png)](https://hivesigner.com/sign/account-witness-vote?witness=arcange&approve=1)</div>
See: Hive libraries for Microsoft .NET now fully support broadcasting transactions by @arcange