Writing Software Contracts for Ethereum — Part 1

Satish Manohar Talim
8 min readJul 17, 2017

--

(Updated on 26th Jan. 2018)

  • In Part 2 we understand some basics of Solidity language and write a simple software contract for Ethereum using Remix.
  • In Part 3 we will setup our private blockchain using geth

Venturing into the world of building smart contracts on Ethereum can be very daunting at first. Where do you start?

Ethereum is really fast moving. This means a lot of the tutorials you will try and follow will not quite work.

My search continues and I have plucked bits and pieces from all over the place and this is what I have come up with.

First, the basics.

The Basics

Who is Vitalik Buterin?

Vitalik is the creator of Ethereum. He first discovered blockchain and cryptocurrency technologies through Bitcoin in 2011. He wrote the Ethereum white paper in November 2013. He now leads Ethereum’s research team, working on future versions of the Ethereum protocol.

What’s a Blockchain?

We have this idiom in the English language that goes something like this: “set it in stone” (we have a pretty high level of trust in stone). A blockchain is really just the above: a kind of material that, through a special mix of cryptography and decentralization, has the properties of permanence, transparency, and neutrality — whatever you put on it. Except now we can do it digitally.

Ethereum is an open source blockchain platform with built in programming language that allows developers to write, test and execute their decentralized application (contract). Data stored on Ethereum blockchain can be viewed by anyone but one having the private key can access it, and is the owner. Any transaction performed is anonymous, parties involved are always unknown.

At the most basic level a blockchain is a digital ledger of transactions, one that is accessible to the public and keeps track of transactions anonymously. It is an open-source software, which means that anyone can see what is happening and make changes to it. What is unique about it is that through cryptography, the recordings are secure and essentially unalterable. At the same time, any changes made to the ledger are distributed globally. Because essentially anyone can participate in and verify the transaction, it puts the power of verification in the hands of those who use it. Blockchain is virtually impossible to hack. This blockchain is not controlled by a central administrator, but instead each node in the network stores its own copy of the blockchain that is shared and visible to anyone within the network.

Image Reference — https://bitsonblocks.net/

In the image above, blocks in a chain refer to previous blocks, like page numbers in a book

Every “block” in this blockchain contains a record of recent transactions, a reference to the block that came immediately before it, and an answer to a difficult mathematical puzzle, among other things.

A blockchain is collectively maintained by “miners”, who are members within the network that compete to validate Ether transactions in each block by solving the complex algorithmic problem associated with the block. They do this by buying or renting lots of computing power to run these complex algorithmic problems on. The incentive for them to use their computing power to verify transactions is that they are rewarded with Ether (shortened to ETH, is Ethereum’s digital currency) if they solve the problem and validate a Ethereum block.

Ethereum Blockchain App Platform’s main page is — https://ethereum.org/

Types of Blockchains

  • Public blockchain like Bitcoin, Ethereum. Public blockchains by nature are open source.
  • Consortium blockchain — example is R3 which is a distributed database technology company. It leads a consortium of more than 70 of the world’s biggest financial institutions in research and development of blockchain database usage in the financial system. Just anybody can’t get involved in the consensus process as one can do in a public blockchain.
  • Private blockchain. A company’s very private information may be kept on this type of blockchain. An example of this is MultiChain.

Is Blockchain a revolutionary piece of technology?

Yes.

With the use of smart contracts (more on this later) on top of the blockchain along with no single point of failure it will be possible to transfer things of value such as property, vehicles etc. very securely (with the power of cryptography). As such this will allow us to transfer very securely things of extreme value. It also cuts out any middle man (Lawyers, Estate Agents etc.) in the above transactions. Also, deals or transactions get completed far quickly.

What’s Ethereum?

Ethereum is software running on a network of computers that ensures that data and small computer programs called smart contracts are replicated and processed on all the computers on the network, without a central coordinator. The small computer programs being run are called smart contracts, and the contracts are run by participants on their machines using a sort of operating system called a “Ethereum Virtual Machine” (EVM).

In other words, Ethereum is an open software developer platform based on blockchain technology that makes it very easy for people to build and deploy decentralized applications (dapps).

  1. Ethereum applications will always, without fail, execute the code they say it will. The code can always be checked. One can personally check and ensure that it does what it says it does.
  2. There is no downtime. These applications are always going to be available.
  3. Ethereum applications are resistant to DDOS attacks.

Previously building decentralized applications required a very good and complex knowledge of Cryptography or cryptology.

  1. Ethereum makes this technology available to all by simplifying it.
  2. Ethereum has a complete programming language, sometimes called EtherScript (though not so popularly used).

How does the change a person makes with a transaction, gets verified by a majority and conformed into the blockchain?

  1. A user makes a transaction and broadcasts it to the network. The entire Ethereum network is a giant mass of nodes (computers) connected to one another.
  2. Nodes (computers) verify that the transaction is correctly signed and if so, pass it to their peers.
  3. A miner’s node will take the transactions with a sufficient gas price (i.e, sufficient transaction fees) and process them to create the contents of the block.
  4. The miner tries random numbers until they find one that, hashed with the contents of a block, proves a sufficient amount of work.
  5. The miner broadcasts the block.
  6. Each node checks the validity of the entire block, from the header to verifying the result of every transaction, and if it checks out, it declares that block valid and passes it on. Otherwise, it ignores the block.

Each node that handles the transaction personally checks to make sure it’s valid. So even if it appears that every other node on the whole network insists that this or that transaction happened, a node can still decide that that transaction was invalid. “Consensus” means that everyone will hopefully reach the same answer eventually, not that nodes necessarily listen to the voice of the majority.

Who is using Ethereum?

Tech giant IBM is building a blockchain-based platform for seven big European banks, including HSBC and Deutsche Bank, that is aimed at simplifying trade finance transactions for small- and medium-sized companies.

Other interested companies include Microsoft, JP Morgan Chase, Deloitte amongst many other large corporations.

Then there is the Enterprise Ethereum Alliance that connects Fortune 500 enterprises, startups, academics, and technology vendors with Ethereum subject matter experts.

Many dapps have already been built on Ethereum — https://dapps.ethercasts.com/

Some of the areas, other than finance, where blockchain is being used are:

Why become a Blockchain developer?

There are five areas in which there is a growing need for blockchain developers:

  • Startups in the Blockchain and Crytocurrency field
  • Corporate Tech Firms like IBM, Microsoft etc.
  • Banks especially global banks
  • Government organizations
  • Professional Services firms like KPMG, Deloitte, PricewaterhouseCoopers (PwC), Ernst & Young (EY) etc.

It is expected that the would-be blockchain developer has an understanding of:

  • You are able to code in different languages especially like Java and C++
  • You are comfortable with Large data sets
  • You have a basic understanding of Crytography
  • You have a basic understanding of the Blockchain

What’s Ether?

Ether (shortened to ETH) is Ethereum’s digital currency.

Every single step in a smart contract is a transaction or a complex computation. Running and storing things on Ethereum would have a cost that is measured in “gas”. The price of this gas is paid by the requester in “Ether”. Ether is the digital currency with which everything runs in the Ethereum (Ether’s price as on 26th Jan. 2018 at 8.50 hrs (IST) was US$ 1,066.59 — https://etherscan.io/stat/supply ). The main reason why people fulfill their end of the bargain in a contract is that they are incentivized to collect Ether.

Ether is the second most valuable Crypto currency after Bitcoin — http://coinmarketcap.com/ and http://coinmarketcap.com/currencies... Ethereum’s technology which we briefly mentioned above is what making Ether’s price shoot up as we go ahead.

Ether has a lot in common with the famous digital currency Bitcoin. Both are a purely digital store of value and means of exchange that cannot be counterfeited. Both are implemented so that no one can manipulate the currency supply. Both can be transferred around the world, like email, and in a very final way, like cash. Both have value today because users expect them to have value tomorrow, and because they can do things traditional money can’t.

It is very important that we have these two things absolutely clear:

  1. Smart contracts are how things get done in Ethereum.
  2. Ether is the currency that is used in the Ethereum network to do anything.
  3. The primary difference between Ethereum and any other cryptocurrency is that it’s not just a currency, it’s an environment. Here anyone can take advantage of the blockchain technology to build their own projects and DAPPS (decentralized applications) through smart contracts.

ETH Units

  1. Just like 1 dollar can be split into 100 cents, and 1 Bitcoin (BTC) can be split into 100,000,000 satoshi. Ethereum too has its own unit naming convention.
  2. The smallest unit is a wei and there are 1,000,000,000,000,000,000 of them per ETH. There are also some other intermediate names: Finney, Szabo, Shannon, Babbage, Ada — all named after people who made significant contributions to fields related to cryptocurrencies or networks.
  3. Wei and Ether are the two most common denominations.
Image Reference — https://bitsonblocks.net/

Where do I buy Ether?

The following sites would help you in buying Ether:

Resources

Videos:

Links:

In Part 2 we will understand Solidity and write a simple software contract for Ethereum using Remix.

In Part 3 we will setup our private blockchain using geth.

--

--

Satish Manohar Talim

Senior Technical Evangelist at GoProducts Engineering India LLP, Co-Organizer GopherConIndia. Director JoshSoftware and Maybole Technologies. #golang hobbyist