.Net and ethereum, first blockchain application.

Blockchain development

Yurii K
4 min readFeb 1, 2021

Plan is simple: make a wallet, send ETH to another wallet and check balance. In our application we are gonna use .net Nethereum library and blockcypher.

First we need to create an account on blockcypher.com. We need that to broadcast our transaction. After registration you will receive a token, without it we can not work with blockcypher api.

In VS code or Visual Studio we create an empty console project. Then we add 2 nuget packages Newtonsoft.Json and Nethereum.Web3.

Nethereum we use to create an address and private key for account. Those data we will store at json file. Our account model contains only 3 properties.

In the Nethereum library we can generate accounts with random secure passwords or we could use our own password.

Account information we store in the json file. For that we need to class for serialization.

For those classes we need another layer. This layer has responsibility to manage accounts: add, remove, save and restore.

We have account addresses now we have to write code to check balance and broadcast our transactions. Blockcypher will help us with that. It has a rest api, we just need to send a request and display a response.

Blockcypher allows us to work with a test ethirum network. We use 3 endpoints: faucet, balance and send raw transaction. Also we need to make models to receive a proper response.

https://www.blockcypher.com/dev/ethereum/#testing — we need faucet
https://www.blockcypher.com/dev/ethereum/#address-api
https://www.blockcypher.com/dev/ethereum/#push-raw-transaction-endpoint

We are using send raw transactions because we can sign transactions in offline mode with a nethereum library.

Everything is ready and we just need to connect everything.

We are making a console application, we are gonna type commands with parameters. Commands will look like this:

So let’s create a command executor and parameter parser.

We need 5 commands: create addresses, save them in file, faucet, check balance and send crypto.

I will make 2 versions of every method with validation messages and without. You can see a full version on git hub.

Create command using our NethereumManager to create users with wallet addresses. In init command we just save the created user in the json file.

Faucet command can give us fake ethirum money. We need to send a wallet address and amount to a blockcypher.

Now we can check our balance using a blockcypher client.

We have cash we should send to somebody else. Using a NethereumManager we sign a transaction. It returns a hex of this transaction, after that we send it to a blockcypher. Easy peasy.

If you need to take a close look at the project here is the link.

Originally published at http://tomorrowmeannever.wordpress.com on February 1, 2021.

--

--

Yurii K

Full-stack developer. In my work, I use Angular and C#. In my free time I write articles for my blog.