You are on page 1of 21

SMART

CONTRACTS

Curs 4
WHAT IS A SMART
CONTRACT?
• Smart contracts are digital contracts stored
on a blockchain that are automatically
executed when predetermined terms and
conditions are met.
WHAT IS A
Smart contracts are simply programs stored on a
SMART blockchain that run when predetermined
CONTRACT conditions are met.

They typically are used to automate the execution


of an agreement so that all participants can be
immediately certain of the outcome, without any
intermediary’s involvement or time loss.

They can also automate a workflow, triggering


the next action when conditions are met.
HOW SMART CONTRACTS WORK

• Smart contracts work by following “if/when…then…” statements that are written into code
on a blockchain.
• A network of computers executes the actions when predetermined conditions have been
met and verified. These actions could include releasing funds to the appropriate parties,
registering a vehicle, sending notifications, or issuing a ticket.
• The blockchain is then updated when the transaction is completed. That means the
transaction cannot be changed, and only parties who have been granted permission can
see the results.
HOW SMART CONTRACTS WORK

• Within a smart contract, there can be as many stipulations as needed to satisfy the
participants that the task will be completed satisfactorily.
• To establish the terms, participants must determine how transactions and their data are
represented on the blockchain, agree on the “if/when...then…” rules that govern those
transactions, explore all possible exceptions, and define a framework for resolving
disputes.
HOW SMART CONTRACTS WORK

• Then the smart contract can be programmed by a developer – although increasingly,


organizations that use blockchain for business provide templates, web interfaces, and
other online tools to simplify structuring smart contracts.
• https://modex.tech/marketplace
• https://mywish.io/
• https://openzeppelin.com/contracts/
BENEFITS OF SMART
CONTRACTS
SPEED, EFFICIENCY AND ACCURACY
• Once a condition is met, the contract is executed
immediately.
• Because smart contracts are digital and automated,
there’s no paperwork to process and no time spent
reconciling errors that often result from manually
filling in documents.
TRUST AND TRANSPARENCY
• Because there’s no third party involved, and because
encrypted records of transactions are shared across
participants, there’s no need to question whether
information has been altered for personal benefit.
SECURITY
• Blockchain transaction records are encrypted, which
makes them very hard to hack.
• Moreover, because each record is connected to the
previous and subsequent records on a distributed
ledger, hackers would have to alter the entire chain to
change a single record.
SAVINGS
• Smart contracts remove the need for intermediaries to
handle transactions and, by extension, their associated
time delays and fees.
USE CASES - SAFEGUARDING THE EFFICACY OF
MEDICATIONS
• Pharma Portal is a blockchain-based platform that tracks temperature-controlled
pharmaceuticals through the supply chain to provide trusted, reliable and accurate data
across multiple parties (IBM & Sonoco)
• https://www.youtube.com/watch?v=eUFVCe_yLpg
INCREASING TRUST IN RETAILER-SUPPLIER
RELATIONSHIPS
• The Home Depot uses smart contracts on blockchain to quickly resolve disputes with
vendors. Through real-time communication and increased visibility into the supply chain,
they are building stronger relationships with suppliers, resulting in more time for critical
work and innovation.
• https://www.ibm.com/case-studies/the-home-depot/
SOLIDITY
SOLIDITY

• Solidity is the main smart contract programming language that is used to build smart
contracts on the Ethereum blockchain.
• It is a high-level programming language that looks similar to Python, C++, and JavaScript.
• It is a contract-oriented programming language meaning that smart contracts are vested
with the responsibility of storing all the programming logic that transacts with the
blockchain.
• The Solidity programming language runs on the Ethereum Virtual Machine (EVM) that is
hosted on Ethereum nodes connected to the blockchain.
SOLIDITY
EXAMPLE
Tutorial

• https://www.tutorialspoint.com/solidity
pragma solidity 0.8.7;
contract VendingMachine {
VENDING // Declare state variables of the contract

MACHINE address public owner;


mapping (address => uint) public cupcakeBalances;
// When 'VendingMachine' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's cupcake balance to 100
constructor() {
owner = msg.sender;
cupcakeBalances[address(this)] = 100;
}
// Allow the owner to increase the smart contract's cupcake balance
function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
cupcakeBalances[address(this)] += amount;
}
// Allow anyone to purchase cupcakes
function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");
require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
cupcakeBalances[address(this)] -= amount;
cupcakeBalances[msg.sender] += amount;
}
}
COMPILING SMART CONTRACTS

• The smart contract must be compiled down to Ethereum virtual machine (EVM) bytecode and
deployed to the Ethereum blockchain for execution
• Solidity Compiler: https://docs.soliditylang.org/en/v0.8.9/installing-solidity.html
SOLIDITY IDES

1.Remix. Remix is considered one of the best IDEs for Solidity.


2.EthFiddle.
3.JetBrains
4.YAKINDU
5.Etheratom
REFERENCES

• https://www.ibm.com/topics/smart-contracts
• https://ethereum.org/en/developers/docs/smart-contracts/
• https://docs.soliditylang.org/en/latest/solidity-by-example.html

You might also like