This article is dedicated to one of the main functions of the Hedera Hashgrapgh Distributed Ledger — the deploying of Solidity smart contracts.

Hashgraph is a distributed ledger technology using the DAG (Directed Acyclic Graph). It has already been used in machine learning (Bayesian network-based trust model), compilers and statistics. In this case, the data is not stored in blocks, but are distributed by events.

DAG systems are also used to solve The Byzantine Generals Problem. As a rule, each project developing a distributed registry has its own way of synchronizing nodes, i.e their own consensus algorithm.

Hashgraph Consensus Algorithm

Each validator collects its transactions, randomly chooses the other participant, and transfers the information about the transactions to the participant, as well as the information that the other nodes have informed when they connected to him.

The functionality is very simple: the validator “listens”, receives all messages that are coming to him, and afterwards, randomly chooses the other participant and sends him all the transactions along with his own.

Hashgraph guarantees that with the final number of steps (rounds of protocol’s work), all nodes reach the same state. The protocol works fast enough and is easily scalable.

In the network, there is no leader. As long as 2/3 honest nodes remain, the protocol secures the high level of safeness.

For nodes to be synchronized and to achieve the agreement between them, there is also an exchange process going between the other participants of the network randomly.

About the Hedera project

A public Hedera Hashgraph network is developing under the guidance of Leemon Baird, using the protocol of the same name. The platform will have file services, wallets and smart contracts in its functionality.

By March of 2019, a crowdsale was completed. The native cryptocurrency of the network, Hbar, is valued at ~$0.12.

Here you can find out more about the network’s state. The mainnet and the testnet are currently avaiable, but the smart contracts of interest to us are available only in testnet at the moment.

Getting started

Registration (KYC)

You must register at the portal and pass the identity proof. It is important! Registration at the portal is possible as part of the testing phase. At the time of publication of this article, the community is awaiting a second round of testing, and registration is unavailable for some time now.

Here are instructions for registration and the KYC process by the link.

Network selection

Let’s choose the network for the following work. The smart contracts functionality is available at the moment only in testnet, so let’s choose the testnet.

Network access

The portal will request that you provide an access code to the network, which can be received via e-mail, by leaving the request at the website.

Enter the code, and Hedera will return the following information:

This data will be needed in the future.

Public and private keys

Upload from GitHub key generator and launch using the command

java -jar hedera-sdk-keygen-1.2-run.jar

We will get:

Deploying of smart contracts

As part of the project, a number of tools were developed (SDK) for creating decentralized applications on the Hashgraph platform. Hedera currently officially supports SDK only on Java. Rust, С, GO, and Python are supported by Launchbadge.

Let’s consider the deploying of smart contract on Java SDK

Let’s begin the deploying of the smart contract, and let’s consider this on the example of the created contract “HelloWorld”. Let’s edit examples

ode.properties.sample. We shall indicate the data that was seen at the portal webpage.

In examples\src\main\resources\scExamples let’s consider the following files:

HelloWorld.sol — the code of the smart contract based on Solidity , for your review

— the code of the smart contract based on , for your review HelloWorld.info.txt — contains the ABI of our smart contract, similarly showed as an example

— contains the of our smart contract, similarly showed as an example HelloWorld.bin — the file with the byte code of the compiled contract is always needed, as we will refer to this file from times to time.

The code of the smart-contact:

pragma solidity ^0.5.3; contract HelloWorld {

function getInt () public pure returns (uint) {

return 42;

}



function getString () public pure returns (string memory) {

return "John says hi";

}

}

Let’s consider the code of the executable file: \examples\src\main\java\com\hedera\examples\simpleDemoContractHelloWorld.java. We will upload the contract to the network and call methods from it.

This line reads the binary code of the contract:

Further below are two methods which we will call from the contract. Note that the constants specify a single-line ABI of the smart contract:

Let’s launch the considered current executed file. We will receive the following:

Congratulations! You have just launched your first smart contract on the Hedera Hashgraph platform!

Referrals: