Hedera Hashgraph Services — Part 3: Smart Contract

Evelyn Wong
Hashing Systems
Published in
5 min readApr 15, 2019

As if the cryptocurrency and file storage capabilities weren’t enough, using smart contracts on Hedera gives even more incentive to use the platform.

Part of Hashgraph’s three core services, smart contracts let users transact on the network without the need for middlemen, more commonly known as trusted intermediaries.

Think of Hashgraph as a vending machine, that upon payment, drops a snack (or product) into the chamber that is now rightfully yours. In this analogy consider the smart contract as the vending software that makes the transaction happen. Removing the middlemen (like the local convenience store owner who has a higher markup on the same snack) keeps costs down and efficiencies high in the transaction.

Consider the literal meaning of a contract. From the sale of a vehicle to a Netflix subscription, terms define what you get for the money you pay. Either party in a transaction can bend or break the rules, from a car not being roadworthy but still being sold. Or the multiple time’s users (quite possibly you) have signed up for free trials using different credit cards at the streaming service and got away with it.

You wouldn’t get away with any such underhand dealings with smart contracts though. They have no need for intermediaries to verify, execute, and enforce transactions and guarantee cost savings, accuracy, safety, backups and storage to boot.

Features

That’s a very brief take on smart contracts. Here we’ll go into more detail on what a Hedera smart contract is made up of:

Initial Balance

There will be an initial balance associated with the smart contract when you create it. The ‘root’ account is where the smart contract will draw funds from.

Proxy Account

Every account has its proxy details

Auto-renew Period

Just as mentioned in the previous two articles that covered cryptocurrency and file storage, the smart contract also has to renew itself every so often via the auto-renewal feature.

One Node Call

A one node call is optional and means that it can enable a non-state affecting function, such as a read-only command to execute on a single node. This obviously is faster, more efficient and costs much less than executing on the whole network.

Admin Key (TBA)

While not implemented at this point and more in the discussion phase, an admin key could not be added to a smart contract that was initially created without one. However, you can create a smart contract with a null admin key. Setting the admin key to null would mean the smart contract would act accordingly and be immutable.

When an admin key is set, keyholders can modify the state of the instance and the field values of a smart contract that is running.

Validation on whether a smart contact had admin keys could be found using as a getInfo query.

Variables

In this section, we’ll discuss a couple of variables that Hedera smart contract has that you should keep in mind.

Gas and gas price

In a smart contract function, gas is used to set a limit on how much the API caller is willing to pay for executing an action or confirming a transaction. A feature of Hedera will refund any overspent gas that’s used beyond what the transaction is required. And in terms of any insufficient gas, it is fully spent before the transaction fails.

Just as with blockchain like Ethereum, the computation must be paid when you send tokens or interact with a contract.

Gas price, on the other hand, is the exchange rate between gas and HBAR, (Hederas own tokens). This rate is set throughout the whole network and not by each individual node. A node cannot reject a request as long as there is a sufficient amount of gas.

Each request is processed based on the consensus order and not processed depending on gas.

Blockchain Comparison

Compared to the blockchain, Hedera Hashgraph doesn’t have block variables in solidity. Hedera Hashgraph has a consensus timestamp instead of a block timestamp. The consensus timestamp focuses on when the majority of the network members received a transaction. Therefore, the interns of the other block variables will mean they default to a fixed value.

For Hedera, shard:realm:id is the format for accounts and smart contract addresses. In terms of accounts and contacts, realms can be seen as a space in a shard, and a shard is a network of Hedera nodes (or computers). A realm is a testing environment within a shard, and therefore developers can execute or run smart contracts in different realms without executions blocking another.

When a specific condition occurs smart contracts can emit events. Hedera Hashgraph has no blockchain. When these events are emitted, they are recorded and kept for 24hrs.

Transactions

After taking a look at the different features on Hedera, let’s go deeper into what exactly can you do to interact with the platform.

Create Transaction

When you create an instance of a smart contract, the contracts functions can be invoked. Create transactions requires you to provide the following attributes:

  • fileID — ID of the file containing the byte code
  • adminKey — the optional administration key(s) for the smart contract
  • Gas — to construct the smart contract if necessary
  • initialBalance — of the smart contract account
  • Constructor Parameters — parameters to pass to a constructor function
  • Proxy details, autoRenewPeriod, shard, realm, newRealmAdminKey

Call Transaction

A call transaction is an execution of a smart contract function. This call transaction requires the following:

  • contractID
  • Gas
  • Amount of tiny bar sent, functions must be payable if not zero
  • functionParameters — parameters for the function call

Update Transaction

The update transaction allows one to update smart contract’s prosperities. Properties of the smart contract may include expirationTime, Proxy details, and autoRenewPeriod.

Queries

There are a few queries you can execute. Executing these queries will allow you to get any information you need on a particular smart contract.

CallLocal

A CallLocal query executes a read-only function on a single node.

GetByteCode

The GetByteCode query returns the byte code for the smart contract.

GetInfo

When calling a GetInfo query, it will return all the smart contract properties to you.

Summary

Smart contracts on the blockchain were revolutionary. Smart contracts on Hashgraph are a game changer. Taking out the middlemen don’t just mean lower costs and higher efficiencies when using ledger technology. It can even have a positive impact on the way commerce and society have worked.

--

--