Create ASP.NET Core Web API for Ethereum DApps

Photo by Verne-Ho

Recently I have discovered Nethereum, an open source library for creating .NET applications which can interoperate with Ethereum and smart contracts. The framework has been actively developed for almost two years now so it is pretty mature and there are a lot of features. Needless to say, I was over the moon :-).

More than two years ago when I first became curious in blockchain (the underlying technology, not cryptocurrency), there was almost no playground for .NET developer. .NET was almost excluded from any blockchain platforms or frameworks have ever been released. Hyperledger Fabric has SDKs for Java, Go, Nodejs; Hyperledger Sawtooth provides SDKs for Python, Go, Javascript, Rust, Java, and C++ (almost all major programming language); Iroha has libraries for Python, Nodejs, Java; Ethereum has implementation in Go, Python, C++, Ruby… Now in late 2018, I’m grateful to see the hard work of .NET community bears the fruits throughout projects such as Nethereum and Nethermind.

So to celebrate, in this article we will walk through a simple project to create a ASP.NET Core Web API, which interoperates with a private blockchain network through a smart contract. The project will make use of Nethereum library for all operations regarding smart contract and ethereum blockchain.

The post will be rather long, so I would divide it into three parts:

Part 1: Set up infrastructure

Part 2: Write a smart contract ERC-20 compliant

Part 3: Create Asp.net Core Web Api for decentralized applications

In the first part, we will see how to set up development environment. It involves downloading and installing SDKs as well as creating a test chain for our project.

The second part briefly introduces an ERC-20 compliant smart contract, how to write one, compile and test. The smart contract will be written in Solidity. The language is pretty easy to catch up (it took me roughly a morning to skim through the docs), but if you feel reluctant, you can just skip the part and use the sample one provided in the project repository. But I really recommend you to take a look because getting your hands dirty in smart contract will help understand many important concepts of Ethereum and EVM.

The third part is probably the most gourmandise. We will create a Web API project using ASP.NET Core and Nethereum. Via this REST APIs, any clients can deploy smart contracts to our private blockchain, and interact with the contracts without the need to understanding the underlying infrastructure. The Web Api acts as a middleman between your front end DApps and blockchain. It is a back-end blockchain enabled decentralized application. The third part will show case some advantages of implementing a front-back architecture for your blockchain applications.

The purpose of the tutorial is to help understand the large picture of how blockchain can interoperate with existing technologies. Therefore the Web API was designed with simplicity and barely any concerns of security. The security subject itself is of great appeal and I will cover it in subsequent articles.

Also, this walk-through will not cover creating client application which consumes the Web Api. There are already a handful of resources out there on how to make a simple Angular or React web app.

The full project is open to access on Bitbucket.

--

--

--

Coder, writer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

LBank Korea initiated the signing ceremony, and DAEX is going to provide the underlying technology…

Trias AMA with Satoshi Club

An introduction to NON- Fungible Token Global Registry (NFTG)

VeChain, Together With Its Partners — DNV GL and Deloitte, Attended the Shanghai International…

Recap D’va with Summeris

Best Crypto Payment For Everyone

What is DeFi?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Huyen Pham

Huyen Pham

Coder, writer

More from Medium

The Basics of NFT Marketplace Development

Project Setup Using Hardhat & Truffle — part 5

Computer screen with code

DAPP using Truffle and React Part-1

Build VueJs with Firebase Project