From the initialization of the network to the execution of a smart contract. The selection of the necessary tools. Here are the main steps for implementing a blockchain application.
The blockchain has passed the course of evangelization. It is no longer necessary to recall the interest represented by blockchain technology. A kind of decentralized account ledger and therefore very difficult to falsify. It allows to validate transactions in near real time without going through a trusted third party. The use cases are endless and many companies have moved from PoC (proof of concept) to concrete achievements.
The underlying technologies are available in open source. Any aspiring developer can implement a small private blockchain on his workstation and run it on a network of a few machines. The opportunity to learn through practice the concepts behind such an environment. Such as mining or the execution of a “smart contract”. The point on the major stages of such a project.
Select your platform
The Ethereum blockchain network is unanimous. Due to the dynamism and responsiveness of its community. The wealth of its documentation. The open source environment proposed has been chosen by almost all companies involved in blockchain projects.
Initialize the blockchain project
To initialize the blockchain, simply create the first block manually. This block must contain all the characteristics of the chain. They will then be shared at all the nodes (or endings) of the network. To define this block, you have to create a file in JSON format.
Several parameters must be specified:
- “nonce” (or random value used by the cryptographic hash).
- “Difficulty” (requirement level associated with cryptographic processing).
- “timestamp” (validation time between two successive blocks)
Once this JSON file is filled in, it is up to the client Geth to create the folder containing the blockchain (chaindata) and to initialize it.
To ensure the propagation of the program, it will be necessary to have cryptocurrency.
The goal is to replicate commands as many times as your network has nodes. The latter being set in agreement with the very first. So that they communicate within the blockchain. It is necessary in a second time to connect them to each other. In order for Geth to connect to a network node and coordinate the set. It must retrieve his identifier called enode on Ethereum.
To ensure the propagation of the node-to-node program on Ethereum. It will be necessary to have cryptocurrency in Gas to acquire the necessary computing power from the actors of the network.
“In the case of a private blockchain, you generate Gas yourself by mining a first block, then a next”.
Says François Zaninotto, CEO of Marmelab.
Choosing the right consensus protocol
The concept of proof of work, which validates and secures the content of blocks. It makes sense in a public blockchain because of the mass and competition between the nodes. On the other hand, there is no reason to be in a private blockchain.
“In essence, the number of actors in a private blockchain is small and they are identified and in this configuration. We will therefore use other consensus protocols”.
For example, evidence-of-stake or proof-of-authority can be used. The latter lends itself more willingly to a private network. “At startup, we will elect the nodes that are authoritative, the majority validating the transaction,” says the expert.
This notion of authority evidence is recent. Similarly, the deployment of configuration scripts has been simplified. “In a configuration file, we indicate the desired number of nodes and the consensus mechanism adopted. Then we execute this file in a command line. All these steps were done manually beforehand”. Released in April 2017 with version 1.6 of Geth, the Puppeth tool (still in development) allows this type of industrialization.
Execute your first smart contract
Mounting a blockchain is only of interest if you can run a “smart contract”. That is, a “smart contract” that self-executes from a predefined threshold that can be a date, an amount, or any duly authenticated event. In the field of public blockchains, this concept made the success of Ethereum.
The reference language for developing such applications on Ethereum is Solidity. “In its grammar, this language is relatively simple and approaches an object-oriented programming environment with notions of class, attribute, function”.
“In addition to Ethereum specificities, when a function is used. For example, each transaction has an issuer, associated costs. The code is also more sensitive, the slightest error has consequences.”
“We do not design a smart contract as a web application”.
As a case study on blockchain, Marmelab has chosen to set up a decentralized advertising server. This was to remove intermediaries between the publisher who offers advertising space on his site and the advertisers. The SQLI agency has used the blockchain to collect the degree of satisfaction of the employees. A test was conducted on ten employees. The results are published on the intranet once the ballot is closed, all without human intervention.
Debug and scale your blockchain
The debugging of a blockchain seems to have marked the minds of those who practiced it. “Unlike a program run by a computer, a block is executed on a set of nodes or network terminations. We know that each must result in a treatment equivalent to those of others,” recalls François Zaninotto. The process makes debugging the application extremely complex. “It is groped on trial / error mode,” said François Zaninotto (read his post on the subject).
Unlike a classic application where a new version overwrites the previous one. Any correction or addition of a feature within a blockchain is historized for life. A smart buggy contract remains stored in the blockchain. You will have to create a new one, to fix the problem, and then wait for the chain to propagate the changes. In the case of open source platforms, the code is constantly evolving. “Then updates tend to break existing smart contracts”.
For all these reasons, the consultant recommends to have his smart contract audited by an expert. A phase that would be all the more essential in the case of a contract deployed on a public blockchain for business purposes targeting customers. The case of the organization The DAO which was stolen the equivalent of 50 million dollars in Ethers because of a bug is in everyone's minds.