See how to easily deploy Ethereum smart contracts using C# and VisualStudio and more
The Story
See how to easily deploy Ethereum smart contracts using C# and VisualStudio and more
Nethereum is the .Net integration library for Ethereum, it allows you to interact with Ethereum clients like geth, eth or parity using RPC
The Story
In a previous article I demonstrated how to use Solidity Visual Studio Extension to be able to implement Ethereum Smart Contracts using Visual Studio or Visual Studio Code.
Now I want to show, when your Solidity Smart Contract code is ready, how you can actually deploy that smart contract code to the Ethereum network using C# code.
What do we do?
So first of all, we need an empty C# Console application (Obviously you can do the same thing in a web app or any other app with C# language).
Then we need to install a nuget package called Nethereum.
Nethereum Nuget packages
I install all of them, except for the Nethereum.Portable one (I think that one has all the others in it as dependency, so if you want you can just download that single one)
Now, is the time to do some coding.
First thing we need to do in the code is to UnLock the account that will be used to create the contract in the Ethereum network. Any gas price or Ethers transferred to the smart contract will come out of this account’s wallet.
Values that are needed are, the Account’s Public Key, Account’s password, and the time we want the account to stay unlocked.
Before we write the code to deploy the contract we need the smart contract’s abi (contract’s interface) and the smart contract’s byecode which you can get after compiling your contract in Visual Stutio Code or Visual Studio.
You can find the abi and the contract’s byte code, in the bin folder of your Solidity Smart Contract folder in Visual Studio or Visual Studio code. The “contractname.abi” file contains the abi json and the “contractname.bin” contains the bytecode of your contract.

Now that you have the abi and the byte code, let’s get back to the code.
After unlocking the account, it is time to deploy the contract. To deploy the contract you need the contract’s abi (json file), contract’s byte code, Ethers you want to transfer to the contract, gas amount, the public key of the user deploying the contract(the account we unlocked earlier) and any argument if your contract has any constructor with parameters.
That’s it. this last line will return a transactioHash which can later on be used to get the actual deployed contract’s public key. If you use the “testnet” network it will take some seconds for the transaction to be approved by the network minders.
Once the contract transaction was confirmed you can use the following code using the “transactionHash” to get the contract information:
There, we deployed our contract to the Ethereum network with C# and we can give this contract address (The contract’s public key) to anyone who is interested to call it’s functions.
I have a test repository in github that puts this all together in an Asp.net mvc application:
aramkoukia/Bethereum
Contribute to Bethereum development by creating an account on GitHub.github.com
Book Recommendation
Here are some book recommendation if you are interested: