Facebook EmaiInACirclel
Software Development

How to Develop Decentralized Applications (Dapps) with the Ethereum Blockchain

PentaGuy
PentaGuy
Blogger

It’s true that the blockchain was initially designed for cryptocurrencies, but Satoshi Nakamoto envisaged a wider scope of application. The emergence of the Ethereum has changed the way people perceive the blockchain. Ethereum is a blockchain designed for the development of Dapps (decentralized applications), whereas the other blockchains are designed for issuing cryptocurrencies based on more evolved concepts of tokens.

Blockchain Technology - Developing Dapps with Ethereum

The blockchain is a disruptive technology empowering companies to digitalize their transactions. Learn more about how the blockchain will transform your business.

Developing Dapps (decentralized applications) involves developing smart contracts

Developing Dapps (decentralized applications) involves developing smart contracts since an Ethereum application is a smart contract.

Nowadays, there is an entire Dapps development ecosystem with various programming languages, the most popular of which is Solidity, an object-oriented language allowing to write smart contracts via a quite simple syntax.

Solidity covers:

  • primitive types,
  • function definition,
  • the notion of heritage,
  • control structures
  • and the possibility to define data structures.

 

How to deploy a smart contract on a blockchain?

Each smart contract has a data area to manage. It is a sort of specific and private hash table of the smart contract that will use it to store a certain amount of information.

Once the source code is ready, it is first compiled in the classic way in order to be deployed on the blockchain. To this purpose, we can use various compilers available on the Internet.

This compiler will have two outcomes:

  • a binary code that will be executed on the VM. And we’re not referring here to a VM in the Java sense, but rather to a program executing compiled bytecode,
  • an ABI (Application Binary Interface) which describes the contract interface and the methods that can be called by other applications or smart contracts.

When deploying a contract, we receive a new address on the blockchain which is the address of the smart contract.

 

Learn more about smart contracts and other innovations powered by the Blockchain

 

What are the characteristics of an Ethereum blockchain?

Contrary to all the other blockchains with a single type of address, the Ethereum has two types of addresses. When looking at the address structure, we see no difference. But when looking at this address in the blockchain, we’ll see:

  • either an account that will be created by an Ethereum user,
  • or a smart contract to which we could send messages.

In the case of a smart contract we can send transactions that will launch an execution on the smart contract whereas in the case of a classic account we can send the Ether.

 

What integrated development environment (IDE) to use to develop Dapps?

Today, we are in the early days of the blockchain, and, in particular, of the Ethereum. IDEs are quite simple. To develop smart contracts, we need at least a Solidity compiler. There are several implementations:

  • solc,
  • solc-js,
  • browser-solidity…

Mix is an open source IDE used for Ethereum development. It embeds publishers for different source codes, a Solidity compiler and different tools for contract testing.

 

The blockchain “disrupts” data centers

The instantiation and deployment of contracts on the public blockchain costs Ethers. The blockchain economic model is meant to “disrupt” data centers.

The idea is that each individual will be able to execute his own nodes and will be remunerated for executing other people’s contracts and applications. Thus each time a node executes a smart contract and validates a block, the nodes that are really executing applications will be directly remunerated. It’s the same as purchasing a VM on Amazon and paying Amazon for executing your applications.

The payment method for executing your applications is defined when deploying the smart contract. You have to pay for deploying the smart contract. This amount of money will be used to remunerate those who execute it.

Moreover, with each transaction sent, the persons using your smart contract and asking it to perform a specific task will pay just a little bit. We call this gas corresponding to the Ether for the Ethereum to execute the transaction.

 

Read more about blockchain transactions

 

The blockchain is similar to decentralized energy smart grid

The blockchain economic model is hyper-distributed. We can compare it to the energy grid where each house will generate a bit of energy. Imagine we could share the energy among all houses in a grid, each of them being both a producer and a consumer. This means we would no longer need EDF centralization. By analogy, there is no need to centralize application hosting. The idea is to have completely decentralized models.

 

How to test a Dapp under development?

Obviously, you’re not going to test your contract by deploying it on the Ethereum public blockchain since, in this case, it’s like you’re really testing it in production and this costs money.

The idea is to create your own private chain where you can also create virtual currencies, but this is what they remain: virtual currencies that cannot be used in the real world and which are only used for testing.

Under development, tests are thus executed on local blockchains.

To ignore these issues, RPC Test is an implementation of the Ethereum “in-memory” blockchain, practical for development and tests. It initializes an Ethereum blockchain with a genesis node with a certain number of accounts and it will give you the private keys of each account.

 

Truffle vs Embark: what development framework to choose for your Dapps?

JavaScript-like frameworks start to emerge in development, especially , which is the most successful one, and Embark.

Truffle will allow you to create a directory. If you type in truffle enit, it will generate the skeleton of an Ehtereum application and of a smart contract + frontend. When you use truffle deploy, it will deploy it on the client that gets executed on your machine. If you have RPC Test, it will execute it locally to see if it works and you will be able to execute unit tests.

These NPM packages offer a classic tool for developers:

  • Automation of the Solidity compilation,
  • Integration to unit test tools,
  • Deployment automation,
  • Blockchain communication.

 

Why use JSON-RPC for your Dapps?

The blockchain is by definition a “closed environment”: the only operations possible are those defined by the EVM.

How to view the data stored by a smart contract?

How to access the data stored outside the blockchain?

How to react to the events occurring in the blockchain?

You will have to develop Dapps that use the same JSON-RPC interface. It is an RPC interface using JSON as a data structure for modelling the data sent to the blockchain.

Different solutions already exist and they all rely on the JSON-RPC interface exposed by the Ethereum nodes. This RPC interface is exposed by all Ethereum nodes, either they are public nodes or testrpc nodes.

The Dapp front end is implemented in JS (single page in js) (Angular 2, …) and uses the web3.js library to communicate with an Ethereum node. The backend (smart contracts) is deployed on the blockchain. The front end is then publicly deployed (Swarm) and the application is available to all the Ethereum users (via Mist, for example).

 

Other advantages of the Ethereum: event management and Oracle pattern

A current need is to execute external code when some events occur in the blockchain. To this purpose, the Ethereum proposes an event mechanism: smart contracts can issue events when executing functions. These events can be monitored from the outside via the JSON-RPC interface.

Certain contracts need to have access to external resources for their execution (REST web service, code execution not supported by the EVM, etc.). We thus need to have an interface between the blockchain and the external world. In the Ethereum, this pattern is called oracle.

 

If you want to learn more about how to leverage Ethereum and the blockchain, contact us. We will be happy to share with you our firsthand experience in building Blockchain-enabled projects.

In the meantime, you can learn more about the blockchain:


Leave a Reply

Your email address will not be published. Required fields are marked *