How does ethereum smart contract work?

admin,May 9, 2018

Cryptocurrency protocols started with Bitcoin in 2009, has become the most well known smart contract in existence. However “Smart Contract” was first introduced by Nick Szabo in 1996.

The name “Smart Contract” is a little bit misleading. They are actually not a contract, like the signed papers we know, and not particularly smart either. “Smart Contract” is a piece of code which runs on the blockchain. Smart Contract is executed exactly like they set up by the creators.

It is Satoshi Nakomoto who gave Bitcoin this feature. Nakamoto gave users an ability to write dynamic public keys and signatures compiled on a program or script.

A smart contract is created on a platform such as Ethereum, for example; a user can create a smart contract to send 50 Ether to a friend on a certain date. This program however, is not used in isolation, rather it can form building blocks for ‘decentralized applications’ (Dapp) or even whole decentralized autonomous companies (DAO).


What you need before creating a smart contract

  • A user account : An address (like bank account number) and a balance
  • A smart account : An address, Ether balance, a state (current state of all fields and variables declared in the smart contract), and code (compiled byte-code that Ethereum clients and nodes can run)


How Smart Contract works

As we know, Bitcoin was the first to support the smart contract system where the network can transfer value from one person to another with the network of nodes validating the transaction once the condition is met.

By contrast, Ethereum replaces Bitcoin’s restrictive language with one that allows the developer to write their own program or script. This program created by a developer, is also called an autonomous agent (as the ethereum white paper calls them), supports a broader set of computational instructions.

Users build “smart contract” by creating :

  • A transaction without a destination address
  • A containing code as a command

A smart contract is likely to need assistance from other smart contracts; when for example, you make a bet if there is a chance of rain in the summer, you need to bring an umbrella. So first you run a contract to check if it is raining today or not, before running the contract to bring an umbrella.

There are also Ether transaction fees for each running contract, which depend on the amount of computational power required. Ethereum runs smart contract code when a user or another contract sends it a message with enough transaction fees. Then, the Ethereum Virtual Machine interprets the contract into a ‘bytecode’ which can be read and run by the network.

The contract which code is executed will create other blocks to be added to the blockchain. This allows the Ethereum blockchain to function as a decentralized virtual computer, on which developers can build applications consisting of multiple smart contracts.


Ethereum’s smart contract system is enabled by two important factors:

  • Gas

As explained above, that the Ether transaction fees depend on the amount of computational power required. It makes developers create smart contracts which are as simple as possible while also preventing abuse and making intensive repetitive attacks financially prohibitive.


  • Solidity

Solidity is a contract oriented, high level language for implementing smart contracts. It was influenced by C++, Python and JavaScript and is designed to target the Ethereum Virtual Machine (EVM).