Bitcoin blockchain is the mother of all blockchains.
It was intended for peer to peer transfer of value and it does that well.
Around 2013, a framework for code execution was introduced by Ethereum Founders.
The centerpiece and thrust of this Ethereum blockchain is a smart contract.
Consider this togged diagram comparing Bitcoin and Ethereum blockchain.
On the left is
the Bitcoin blockchain and a wallet application for initiating transactions.
On the right is Ethereum that took
a significant step towards transforming the blockchain into
a computational framework that opened up
a whole world of opportunities in the decentralized realm.
Ethereum supports smart contracts and of
which will machine on which smart contracts execute.
Smart contracts in turn enable
decentralized application that accomplish more than a transfer of value.
Efficient automation of decentralized application such as supply chain.
Smart contract is an important topic that we have
allocated a full course for this topic in this specialization.
In this module, of course, one,
we provide a high level overview of smart contract as it relates to Ethereum.
After completing this module on Ethereum,
you will be able to discuss at a high level the integration of the ethereum blockchain,
namely the smart contract.
Illustrate ethereum blockchain protocol,
structural elements, and operational aspects.
Demonstrate the concept of gas,
the fuel or the payment model for
code execution and the incentive model for the Ethereum blockchain.
What is a smart contract?
Let's review the basics.
A smart contract is a piece of code deployed in the blockchain node.
Execution of a smart contract is initiated by a message embedded in the transaction.
Digital currency transfer request simple addition and subtraction.
Ethereum enables transaction that may carry out more sophisticated operations.
For example, a transaction could require a conditional transfer,
it may require some evaluation,
it may need more than one signature for transfer of assets,
or it may involve waiting for a specific time or date.
Let's consider an example of what a smart contract can do.
An auction bidding smart contract could execute this logic.
If the age of a bidder is greater than 18 and the bid is greater than the minimum bid,
then, accept the bid,
or else reject the bid.
This can be done by a smart contract.
What does the smart contract look like?
How do you write a smart contract?
Structurally, a smart contract resembles a class definition in an object oriented design.
It has data, functions or methods with modifiers public or private,
along with getter and set of functions.
Specific programming languages have been designed for coding smart contracts.
Solidity is one such language.
Let's examine a simple Solidity smart contract to understand its structure.
First line with pragma indicates the version of the solidity language.
The contract's name is in the first line.
This particular contract is for one integer storage.
The data for the integer is defined with type a name, uint StoredData.
Two functions are defined for writing and reading the data.
Set and get. Code execution.
Where does the code in the smart contract get executed?
Where is it located in a node?
We need a computational infrastructure to execute any arbitrary code.
Every node in Ethereum network should be able to execute the code
irrespective of that underlying type of hardware or operating system.
Enter Ethereum Virtual Machine, EVM.
An EVM provides a run anywhere obstruction layer for the contract code.
A smart contract written
a high level programming language is translated into EVM byte code,
and then, deployed on the Ethereum Virtual Machine, EVM.
Every node will host the same smart contract codes on the EVM.
Summarizing, smart contracts add a layer of
logic and computation to the trust infrastructure supported by the blockchain.
Smart contracts allow for execution of code.
Enhancing the basic value transfer capability of the Bitcoin blockchain.
The code for this smart contract is written in
a high level language like Solidity and compiled into byte code.
The code for the smart contracts is executed on
a special structure known as Ethereum Virtual Machine.