How Do Ethereum Smart Contracts Work

smart contracts.jpeg

 

Most of us must have used the term ‘Smart Contracts’ in a blockchain discussion with colleagues or friends without completely realising the impact Smart Contracts can have on the entirety of the socio-economic framework our society thrives on.

We have mentioned multiple times in this blog that Blockchain as a technology is revolutionary.

We refrain from calling ourselves maximalists of any particular cryptocurrency. Rather, you may call us blockchain/crypto maximalists.

Coming back to the topic at hand, you may already know by now what Blockchain is and how it works. If not, feel free to read our previous blog posts. Now, let us delve into a more intriguing topic of what are smart contracts.

 

What are smart contracts

Quoting Wikipedia,

“A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract. Smart contracts allow the performance of credible transactions without third parties. These transactions are trackable and irreversible.”

The above definition basically states that smart contracts as the name suggests are contracts that can be programmed, verified without third parties, are trackable and are immutable unless explicitly mentioned in the contract.

There are numerous blockchain platforms that let you create custom smart contracts for varied use cases. Some of them are Ethereum, Hyperledger fabric, R3 Corda, Stellar, Achain, etc.

 

How do smart contracts work

We will now try to understand smart contracts right from its inculcation.

Smart Contracts were first introduced by cryptographer and Computer Scientist Nick Szabo in 1994. A rough idea of smart contracts could be understood by analysing vending machines. You select a particular snack and enter the appropriate amount into the machine, the snack then presents itself to you. Just like that, magic.

However, sometimes the machine fails (mainly because of poor programming and centralisation), something which is tackled very efficiently when it comes to blockchain.

A Smart Contract needs several mathematical moving parts for it to function seamlessly.

  1. A Blockchain platform – for it to perform and verify transactions on chain
  2. Public Keys and Private Keys – the Smart Contract must have access to the private keys that it plans on controlling.
  3. Conditions – Clear conditions must be defined by the Smart Contract so that relevant transactions are carried out. (a simple if loop on the blockchain)

Smart Contracts are highly beneficial in a wide variety of domains as they let you create contracts that are secure, fast and are standardized for numerous use cases.

The use cases of smart contracts are so vast that we would probably need more than one post to elaborate on each of them. However, we will try to cover as much as possible in one post.

We will define this with 3 different examples that will adopt Smart Contracts in growing stages.

  1. Minimal
  2. Partial
  3. Complete

Let’s take a real-life scenario where smart contracts could possibly be used in the near future. In this example, we will consider Uber. Uber, as we all know, are disruptors of traditional taxis and are probably the largest cab hailing service in the globe. Smart Contracts potentially have the capability of disrupting this disruptive service.

 

Minimal

In this scenario, we will modify the payment system that Uber uses after completing a ride. You will ideally link your credit card to Uber which automatically deducts the fees when your ride completes.

If you do not prefer digital money, you will pay cash to the Uber driver based on the amount that shows up on your phone. Uber runs an algorithm that calculates how much fees should be charged to the rider based on the distance covered and the traffic/wait time.

Now, this can be completely automated if linked with a smart contract.

At the end of each ride, Uber will send a message to the smart contract linked with your profile and the appropriate amount gets deducted seamlessly. This use case is much similar to current day credit cards, however, Smart Contracts are more secure.

 

Partial

In the Partial scenario, we take the application of Smart Contracts up a notch and eliminate human drivers completely.

With the innovation Tesla, Uber and Google are doing on the grounds of self-driving cars, it isn’t long until you see self-driving private cars and cabs doing everyday rides on the freeway.

Now, imagine you book an Uber and it turns up to be a self-driving car. At the end of your ride, a Smart Contract can be programmed such that the fees charged are deducted directly from your crypto wallet and only after the payment of fees, will the doors of the cab open.

The Uber cab may have one or many owners and the fees will then get transferred to their accounts based on the logic written in the smart contract.

 

Complete

Now, this scenario is utopian and far-fetched but the possibilities of this happening cannot be outright denied.

In this scenario, an Uber is not owned by anyone but itself. The car in and of itself is a decentralised autonomous entity. This concept is adapted from ‘Internet of Money’ by Andreas Antonopoulos. (Highly recommended read)

Consider a self-driving car that has no owner. All the rides that it takes go towards the maintenance and fuel costs that it has to undertake. It saves the excess money for major upgrades or unforeseen circumstances.

But the car essentially has no owner and all the money it gets from rides can be used for varied purposes, all determined purely by the car on its own.

When you hail a ride from such a vehicle, at the end of each ride, the smart contract automatically deducts money from your wallet and sends it to the DAE (Decentralised Autonomous Entity), which is your Uber in this case.

The Uber then uses the same money for fuel or maintenance which again makes the use of Smart Contracts.

Uber or self-driving cars is one such example. You can put numerous transactions on the Smart Contract, including real estate transactions.

Smart contracts have use cases in everyday lives. Things you couldn’t imagine without the internet now; in the future, you wouldn’t imagine it without Smart Contracts!

Another real-life use case of Smart Contracts is how BBOD settles transactions on your Ethereum wallet.

We run a proprietary non-custodial smart contract using which you can trade on BBOD without transferring funds to the central wallet. Your funds stay safe in your very own Ethereum wallet.

We hope this blog post gave you a brief idea of how Smart Contracts work. In future posts, we will explore more in and around the blockchain ecosystem. Stay tuned!

 

How To Create An Ethereum Wallet Using Metamask

 

This post walks you through the setup process of MetaMask in Google Chrome. We choose Chrome as it is more widely used than any other browser. However, the process to install MetaMask plugins in Firefox and Opera is also the same.

 

What is Metamask?

MetaMask is essentially a browser plugin that is supported by Chrome, Firefox and Opera. It lets you set up your very own Ethereum wallet right in your browser. You can make transactions into and out of your Ethereum wallet with ease using MetaMask.

 


Step 1: Go to https://metamask.io/


 

Click on the GET CHROME EXTENSION button which is highlighted in the below image.

 You can select Firefox or Opera right below the highlighted box if you use those browsers. The steps that follow are similar. You will be asked to add the MetaMask Extension to your respective browser.

You can select Firefox or Opera right below the highlighted box if you use those browsers. The steps that follow are similar. You will be asked to add the MetaMask Extension to your respective browser.

 


Step 2: Install MetaMask Extension


 

Click on the ADD TO CHROME button to add it to your chrome extension list.

 The browser will check the compatibility and a dialogue box will pop up as shown below. Click on the Add Extension button to proceed.

 

The browser will check the compatibility and a dialogue box will pop up as shown below. Click on the Add Extension button to proceed.

 

Picture3.png

 

Step 3: MetaMask added successfully!


You have now successfully added MetaMask to your browser. Congratulations!

 

Step 4: Open MetaMask


Open a new tab and click on the small orange fox icon in the top right corner of the browser as shown in the below figure.

Picture5.png

 

Step 5: Accept Terms


 This will open a popup window with details. The Accept button will be greyed out. You can either read the Terms of Use or scroll to the bottom of the pop-up window as shown in the below images.

 Note - let's be honest, who reads terms and conditions anyway? Well, terms and conditions are extremely important because they provide information about the product and terms of use. Never ignore them.

Note – let’s be honest, who reads terms and conditions anyway? Well, terms and conditions are extremely important because they provide information about the product and terms of use. Never ignore them.

After you have read the Terms of use, click on the Accept button highlighted in the below image.

Picture7.png

This will be followed by a bunch of terms that you should read and accept as shown below.

Privacy Notice

Picture8.png

Phishing warning

Picture9.png

 

Step 6: Create a Wallet


You must now enter a secure password with at least 8 characters in the boxes provided.

Picture10.png

After entering the password and before clicking the create button as shown in the below figure, please take your time to understand the look and feel of the MetaMask fox as he follows around your mouse pointer. Pretty neat design, eh?

Picture11.png

 

Step 7: Wallet Seed Words


You will now come across 12 words that let you restore your MetaMask accounts. Make sure you keep them safe and secret. I have masked the words below except for the last word economy, for flair. You can either choose to copy the words somewhere safe or save it as a file in your computer. Both options are present as buttons below.

Picture12.png

 

Step 8: Congratulations! Wallet created!


You now have a MetaMask wallet!

 Clicking on each of the options mentioned will perform a particular action.

Clicking on each of the options mentioned will perform a particular action.

  • View account on Etherscan – This will take you to Etherscan.io where you can see all the transactions that have happened on your public address.
  • Show QR Code – This will show your public address as a QR code.
  • Copy Address to Clipboard – This copies your public address to your clipboard.
  • Export Private Key – This is very IMPORTANT as access to the private key determines access to your wallet.

You can also edit your wallet name to whatever you want by clicking on the edit option. I have changed it to ‘My First ETH Account’ as shown below.

 

Step 9: Public and Private Keys


You can now view your public and private keys. DO NOT SHARE YOUR PRIVATE KEYS with anyone.

The following screenshots show public keys and private keys (which are hidden because they shouldn’t be shared)

Public key

Private Key

 

Step 10: MetaMask Wallet Overview


You can now do transactions in ETH directly from your browser! You can explore the BUY and SEND buttons as shown in the below steps.

 

Step 11: Buy / Send ETH


 You can buy ETH from Coinbase or Shapeshift as shown below.

COINBASE

Picture18.png

 

SHAPESHIFT

Picture19.png

You can also send ETH to other recipients by specifying their addresses and the amount you want to send.

Picture20.png

 

This concludes the MetaMask setup tutorial. 
Hopefully, this brief tutorial successfully helped you create an Ethereum wallet on your browser using MetaMask.