Nethereum – A .NET Library for Ethereum


Nethereum is the .Net integration library for Ethereum, it allows you to interact with Ethereum clients like geth, eth or parity using RPC. The library has very similar functionality as the Javascript Etherum Web3 RPC Client Library (from GitHub documentation).

Nethereum is the open source library that is actively built at GitHub.

I am using Nethereum to programmatically deploy the smart contracts and send transactions to these contracts. In this blog, I will walk through setting up the Visual Studio deployment environment. Below are the simple two-step process to setup the Visual Studio Development Environment using Nethereum

Step 1: Create an ASP.NET Core Web Application

Step 2: Install the Nuget Package Nethereum.Geth

Now we are ready to use C# with Ethereum.


Setting up Ethereum Rinkeby Testnet

Rinkeby is the public testnet for Ethereum. This testnet can be used during development, testing and pre-production scenarios. I personally use private net during development and use Rinkeby for demos.

Refer to my other blog on setting up a development private chain: Ethereum Dev Network

Here are the steps for setting up and connecting to Rinkeby test chain:

Step 1: Download the latest Geth from the below URL

As I am using a windows machine, I downloaded the windows version. Install the Geth on your machine as per the installation guide.

Step 2: Create a folder called Rinkeby which keeps the chain data.

Step 3: Run the following command to connect to the Rinkeby testnet
geth.exe --rinkeby --syncmode "fast" --datadir=devchain --rpc --rpccorsdomain "*" --rpcapi "eth,web3,personal,net,miner,admin,debug" --verbosity 0 console

Step 4: Wait for the sync to complete. The sync will be completed based number of blocks. With the current block number 586,326 it took about 20 mins to sync. You can check the sync status with the following command:
eth.syncing

The above command returns either false (if syncing has not stated or completed) or current block number. Wait for the syncing to be completed.

Step 5: Create the user account using the javascript console. Run personal.newAccount() and provide password when prompted

The console shows the address of the new account created.

Step 6: Verify that your account is created in the Rinkeby by using the Rinkeby Etherscan


Step 7: Request Ether(ETH) for your newly created account. As you see above the current ETH balance is 0. Rinkeby uses Proof of Authority for mining. Hence you need to request Rinkeby to provide you ether. Rinkeby has a faucet which can provide you ether. You need to periodically request Ether using this faucet.

To prevent spam, Rinkeby faucet requires people requesting funds have a GitHub account and create a GitHub Gist. Let’s create a GitHub Gist with the account number as shown below:

Once the Gist is created go to the Rinkeby faucet (https://faucet.rinkeby.io/) and request funds

Once the account is funded with your requested ethers, go to the Etherscan and verify that the account is credited with the requested ethers.

With these above seven steps, our Rinkeby testnet is setup and ready to deploy smart contracts and send transactions.


Smart Contracts (Solidity) coding using Visual Studio Code


Visual Studio Code is the open source editor with powerful developer tooling. It works on Windows, Linux and Mac. Visual Studio Code is also a great editor for developing of smart contracts with Solidity. VS Code provides syntax highlighting, compilation of current contract and all contracts.

If you haven’t downloaded Visual Studio Code, download and install code from the below link.

For developing Solidity using Visual Studio Code you first need to install the Solidity Extension. For that open Visual Studio Code and using menu click View -> Extensions and search for Solidity and click install. Once the extension is installed you can start coding solidity smart contracts.

To compile the contract click F5. If there are no error messages, you will get the success message as shown below:

If there is a compile error then the error is highlighted as shown below

Overall Visual Studio Code is a good editor for developing smart contracts for Ethereum.

Ethereum a decentralized database


The database we know and used so far are centralized in nature. That is we have one big database server which stores data. SQL Server, Oracle, DB2 etc are some of the popular databases. This database technology has been evolving since 80s. Now with the advent of Blockchain, there is a significant shift in the database technology.

Ethereum, in general Blockchain, is the new kind of database. It is a distributed peer to peer replicated database. Each Ethereum node will have a copy of the database. Ethereum will make sure that the database is in sync across all node, that every transaction is replicated and synced across all participating nodes. Every Ethereum node will have the same exact copy and there is no need to cross check.

Below are typical characteristics of Ethereum decentralized database:
  • Decentralized control. There is no central authority to manage and maintain database
  • Immutable. Once the transaction is sealed inside a block and the block is added to the chain, the transaction cannot be modified
  • Scalability. Ethereum is a highly scalable architecture. It can be easily scaled by adding additional nodes
  • Fault Tolerant. As Ethereum is distributed in nature, if a node goes down, the other nodes in the network automatically picks up the transaction

Unlike central database technologies, Ethereum uses consensus approach for committing transactions. When the user performs a transaction, in the traditional way this transaction is sent to the database and the database commits this transaction. In the Ethereum way, this user transaction is sent to the connected node. The node then broadcasts the transaction across the network of distributed nodes. Each node that receives this transaction personally checks that the transaction is valid. So every node in the network comes to a consensus about the transaction. As you see Ethereum (or blockchain) changes the paradigm of transactions. It transfers the authority of transaction to the decentralized network. Due to this Ethereum is sometimes called as distributed ledger.

All centralized databases provide programming capabilities with stored procedures. Ethereum also have similar functionality. It is called as Smart Contract. A smart contract is class that can have multiple methods that interact on the data persisted by smart contract. These classes can resemble the package concept in Oracle and the methods in the smart contract are similar to the procedures within the package. So smart contracts in Ethereum resembles to packages in Oracle. These smart contracts can also be similar to the database constraints.
  • Ethereum promises to eventually change the database we know. But here the current limitations of this new technology:
  • Query capabilities: Databases are known for their querying capabilities. Ethereum lacks this basic capability.
  • Rich permissioning: Databases provide very granular permissions. By default Ethereum is designed to be public in nature, hence it provides basic permissions. There is a special fork by JP Morgan, Quorum, which provides permissioned Ethereum chain.
  • Low latency: Due to the distributed and decentralized in nature, Ethereum adds significant latency.

As you see with the current state of Ethereum, it has advantages and disadvantages. So we can pair up Ethereum with database and can reap the benefits of both the world.


Ethereum Solidity Compiler

Ethereum contracts are written in the high level language called Solidity and compiled into bytecode using the Solidity compiler. This ...