Introduction
to Smart
Contracts
What Is A Blockchain?
● A blockchain is a ledger that keeps a shared record of all the transactions
distributed over a vast network of users.
● Key aspects of blockchain are-
○ Decentralization
○ Immutability
○ Trustless
○ Transparency
What are smart contracts?
● A smart contract is a program whose execution is
○ Decentralized
○ Immutable
○ Trustless
○ Transparent
● Analogous to traditional contracts,
○ A smart contract is an agreement that can be enforced through a blockchain.
● An example of a smart contract can send, receive and store money.
● It can also interact with other smart contracts or any computational systems
connected to the internet.
Traditional contract
Smart contract
Bitcoin also
supports smart contracts!
Smart contracts on bitcoin?!
● It's worth noting that bitcoin was the first to support basic smart contracts
○ network can transfer value from one person to another
○ network of nodes will only validate transactions if certain conditions are met.
● Multisig smart contracts, using features added to Bitcoin through
improvement proposals
● Smart contract functionality is not as programmable and extensible on Bitcoin
Intro to Ethereum
● Platform similar to Bitcoin but:
○ Ethereum uses Ethash(KECCAK-256) algorithm while bitcoin uses
sha256.
○ The block time is 12 seconds while in Bitcoin is 10 minutes.
○ Ethereum uses a Turing Complete programming language owing to
which almost any sort of algorithm can be written.
Ethereum Virtual Machine (EVM)
● Ethereum Virtual Machine is an environment which runs at an abstraction
layer straight above the underlying hardware.
● Ethereum uses its Turing Complete Virtual Machine for running and compiling
the codes.
● Any type of algorithm can be written in ethereum.
More examples of smart contracts
● Function as 'multi-signature' accounts, so that funds are spent only when a
required percentage of people agree
● Manage agreements between users, say, if one buys insurance from the
other.
● Provide utility to other contracts (similar to how a software library works)
● Store information about an application, such as domain registration
information or membership records.
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts

Introduction to Blockchain and Smart Contracts

  • 1.
  • 2.
    What Is ABlockchain? ● A blockchain is a ledger that keeps a shared record of all the transactions distributed over a vast network of users. ● Key aspects of blockchain are- ○ Decentralization ○ Immutability ○ Trustless ○ Transparency
  • 3.
    What are smartcontracts? ● A smart contract is a program whose execution is ○ Decentralized ○ Immutable ○ Trustless ○ Transparent ● Analogous to traditional contracts, ○ A smart contract is an agreement that can be enforced through a blockchain. ● An example of a smart contract can send, receive and store money. ● It can also interact with other smart contracts or any computational systems connected to the internet.
  • 4.
  • 5.
  • 6.
  • 7.
    Smart contracts onbitcoin?! ● It's worth noting that bitcoin was the first to support basic smart contracts ○ network can transfer value from one person to another ○ network of nodes will only validate transactions if certain conditions are met. ● Multisig smart contracts, using features added to Bitcoin through improvement proposals ● Smart contract functionality is not as programmable and extensible on Bitcoin
  • 8.
    Intro to Ethereum ●Platform similar to Bitcoin but: ○ Ethereum uses Ethash(KECCAK-256) algorithm while bitcoin uses sha256. ○ The block time is 12 seconds while in Bitcoin is 10 minutes. ○ Ethereum uses a Turing Complete programming language owing to which almost any sort of algorithm can be written.
  • 9.
    Ethereum Virtual Machine(EVM) ● Ethereum Virtual Machine is an environment which runs at an abstraction layer straight above the underlying hardware. ● Ethereum uses its Turing Complete Virtual Machine for running and compiling the codes. ● Any type of algorithm can be written in ethereum.
  • 10.
    More examples ofsmart contracts ● Function as 'multi-signature' accounts, so that funds are spent only when a required percentage of people agree ● Manage agreements between users, say, if one buys insurance from the other. ● Provide utility to other contracts (similar to how a software library works) ● Store information about an application, such as domain registration information or membership records.

Editor's Notes

  • #10 A computer is Turing complete if it can solve any problem that a Turing machine can, given an appropriate algorithm and the necessary time and memory. Informally, however, calling something Turing complete means that it can execute any algorithm
  • #13 The first line specifies the compiler version for which the contract code is written. Carrot signifies that code is written for version 0.4.0 or any newer version that does not break functionality i.e upto 0.5.0. The smart contract will be compiled to bytecode. Bytecode is stored on the ethereum ledger along with this initial state of the contract is also set up as per the constructor code by the Ethereum Virtual Machine. Contract keyword simply defines a class. Here name of class is simple storage. Here no constructor and so the state, here it is stored data will be set to zero. There are mainly two types of functions read functions and write functions. set() function here is a write function because it updates the state of the contract. get() function is a read function as it is just returning the variable without changing any state.
  • #14 Address is a type like uint and stores ethereum address of size 160 bits. Mapping keyword refers to the type hashmap, here balances mapping stores coin balance corresponding to an address. Public keyword makes these variables readable from outside i.e a getter function is automatically compiled. For eg: anyone from outside can simply call the minter() function and that will return the current minter address. Events allow the convenient usage of the logging facilities. Here Sent event is defined which logs the address of sender receiver and the number of coins transacted. When send function is called it updates the state and also emits the sent event which can be listened by the user interface of a javascript dApp. “msg” is a global magic variable that stores properties such as the transaction sender’s address, function identifier, calldata, ether value sent to the contract. Here msg.sender refers to the transaction sender’s address. Different type of function modifiers are public - all can access external - Cannot be accessed internally, only externally internal - only this contract and contracts deriving from it can access private - can be accessed only from this contract Constructor sets up the minter variable value equal to the address of account that deployed this smart contract. Mint function can mint coins to a receiver address. If anyone could call this function that will be a problem. We add a condition such that only the smart contract owner can call this function. Send function simply transfers coins from sender’s address to the receivers address. Sender can send only if he has that many tokens in his account . This transaction has to be atomic i.e it is either complete or if there is any issue at third line the complete state would revert.