Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Implementation and Deployment of Smart Contracts on Ethereum

Implementation and Deployment of Smart Contracts on Ethereum

This talk was presented at Developer Circle Kampala at Outbox Hub.

This talk coverered Implementation & Deployment Of Smart Contracts on Ethereum.

Requirements: VScode(or any other IDE), Python3, Pip, Virtualenv, Make, Docker

By: Asindu Wilfred

Event: https://www.facebook.com/events/216138855609855/

Developer Circle Kampala

March 22, 2018
Tweet

More Decks by Developer Circle Kampala

Other Decks in Technology

Transcript

  1. SMART CONTRACTS ON ETHEREUM 22nd March 2017 | Facebook Developer

    Circles Kampala | OutBox, Soliz House By Asindu D. Willfred @as1ndu [email protected]
  2. What is a smart contract? ▪ A smart contract is

    basically a piece of software/hardware that can be used to enforce agreements made between two parties. ▪ Analogous to Boom barriers in shopping malls: 1. Entering the facility is free — opens automatically 2. If you use the parking space of the facility less than 1 hours — It lets you out for free 3. If you use the facility for more than 1 hour — It will not let you out unless you pay a fee fee = hours_spent_in_parking_space*fee_per_hour Boom Barrier in action
  3. What Ethereum is (Generic explainer) ▪ Ethereum is a decentralized

    platforms that can execute “Turing complete” software securely i.e it offers features like censorship resistance. 1. It runs globally on thousands of nodes 2. Anyone can setup an node by running the Ethereum client. 3. Anyone can validate the integrity on content stored on the Ethereum platform 4. “Turing complete” just means, if a piece of software can run on your laptop, it can run on Ethereum.
  4. Ethereum’s Components: Addresses ▪ Look like 0x2a65Aca4D5fC5B5C859090a6c34d164135398226 ▪ In hex

    format ▪ Made the last 42 characters (20 bytes) of this public key ▪ Created by; 1. Generating a random private key 2. Using private key to create public key 3. Choosing the last 40 characters of public key 4. Prefix the last 40 characters with “0x”
  5. Ethereum’s Components: Ether ▪ The digital commodity on Ethereum aka

    “fuel” for smart contracts ▪ Symbol — Ξ ▪ Ticker symbol — ETH ▪ Subunits 1: wei 1012: szabo 1015: finney 1018: ether
  6. Ethereum’s Components: EVM ▪ EVM is the Ethereum Virtual Machines

    ▪ It is a tiny CPU implemented in software that all Ethereum nodes run
  7. How smart contracts work on the EVM Public Key Cryptography

    Hashing algorithms Game theory Virtual machine Ethereum
  8. Why we need smart contracts on a blockchain? ▪ Reduce

    counterparty risk: Two entities working together with out one having to trust another to take control over infrastructure/resources ▪ Reduce on rent seeking : Can we remove Salaries, recurring subscription fees & commissions? ▪ Censorship resistance: Tamper proof/immutability/security
  9. Setting Up the the EVM & Vyper ▪ $ docker

    build https://github.com/ethereum/vyper.git -t vyper:1 ▪ $ docker run -it vyper:1 /bin/bash Or we can Just skip that and use https://vyper.online/ ☺
  10. Introducing Viper ▪ I don’t like JS so I hate

    statically typed JS (which solidity basically is) ▪ Very Pythonic ▪ Very legible
  11. Vyper Syntax: State Variables ▪ Varibles are how you store

    stuff in Vyper ▪ Forexample if you want to store Mobile Money Credit data using Vyper Variables are declared as: MobileMoneyCredit: int128 ▪ “MobileMoneyCredit” is the case sensitive variable name. ▪ “Int128” is the variable Type in in Ethereum, variables can be can have type of of; “string” — For storing text “int128” — For storing both positive & negative integers “uint256” — For storing only positive integers “decimal” — For storing numbers with decimal places “bytes32” — For storing arrays/lists “bool” — For storing True/False statements * And possibly more
  12. Vyper Syntax: Functions ▪ Functions are defined with “def” keyword

    ▪ Functions must be decorated with “@public” or “@private” @public — used in case you want a contract to be both called externally & internally @private — used in case you want a contract to be only called internally ▪ The @payable decorator should only be used if you want the contents of a contract to be transferable example code of a function is as below @public @payable def send(): // statements go here }
  13. Vyper Syntax: Arithmetic Operators x + y Addition x -

    y Subtraction -x Unary minus/Negation x * y Multiplication x / y Divison x % y Modulo min(x, y) Minimum max(x, y) Maximum floor(x) Largest integer <= x. Returns int128
  14. Compiling Vyper code via the command line. ▪ $ docker

    run -it vyper:1 /bin/bash ▪ vyper yourFileName.v.py ▪ Or Lets use https://vyper.online/
  15. A look at compiled Vyper code: ABI ▪ ABI is

    the Application binary interface ▪ Bridge between machine code & Vyper ▪ A list of the contract's functions and arguments (in JSON format) ▪ An account wishing to use a smart contract's function uses the ABI to hash the function definition so it can create the EVM bytecode required to call the function. Example: [{"name": "__init__", "outputs": [], "inputs": [{"type": "address", "name": "_beneficiary"}, {"type": "int128", "name": "_goal"}, {"type": "int128", "name": "_timelimit"}], "constant": false, "payable": false, "type": "constructor"}, {"name": "participate", "outputs": [], "inputs": [], "constant": false, "payable": true, "type": "function", "gas": 60994}, {"name": "finalize", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 26419}, {"name": "refund", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 2010401}]
  16. A look at compiled Vyper code: Bytecode ▪ Is the

    code that will run on the Ethereum Virtual Machine ▪ Contains instructions as outlined in the specification via the Yellow paper Example code: ▪ 0x600035601c52740100000000000000000000000000000000000000006020526f7ffffffffffff fffffffffffffffffff6040527fffffffffffffffffffffffffffffffff800000000000000000000000000000006060 5274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e0000000000000 00000000000000000000060a05260606103986101403934156100a757600080fd5b6020610 39860c03960c05160205181106100c057600080fd5b50606051602602060c0200160c052602 060c020015461016051600060c052602060c0200160c052602060c020546000f16101d75760 0080fd5b61016051600060c052602060c0200160c052602060c02060008155600060018201 55505b8151600101808352811415610176575b5050606051601e6101405101806040519013 5857809190121561022d57600080fd5b600555005b5b61014d6103800361014d6000396101 4d610380036000f3 *fun fact, some people can read this
  17. What is Geth? ▪ Its an implementation of the Ethereum

    client in the Golang programming language. ▪ Most popular ▪ Contains a comprehensive suite of ethereums’s features like Swarm, EVM & Wisper
  18. Running Geth ▪ Use the $ geth ▪ You will

    see; Mac/Linux $INFO [11-13|15:28:12] IPC endpoint opened:tmp/ethereum_dev_mode/geth.ipc Windows: >INFO [03-22|12:21:24] IPC endpoint opened: url=\\\\.\\pipe\\geth.ipc ▪ Then run; Mac/Linux $ geth attach /tmp/ethereum_dev_mode/geth.ipc Windows >geth attach ipc:\\.\pipe\geth.ipc
  19. Lets walk through these pieces of code ▪ Crowdfunding Smart

    contract ▪ Hello World ▪ Decentralized SACCO
  20. Time stamping research papers Using block time on Ethereum to

    time stamp academic research papers. ▪ Proof of who did research first. ▪ Attempts to combat Plagiarism.
  21. Lands Registry ERC 721 for land titles (none fungible tokens

    for Land) ▪ Allows speculative market places for plots of land ▪ Inability to double spend possibly reduces land fraud ▪ Immutability may also lead to less forceful taking
  22. University Transcript Validation ▪ Allows employers to independently verify academic

    credentials. ▪ Employment history validation can also be done independently ▪ Can exist in form of a hash/transaction id that originates from the previous academic institution/employer
  23. Patents Registry Immutable database for dating of patents & intellectual

    property ▪ Similar to research papers ▪ Proof your invention was first & was not stolen
  24. Scaling ▪ Possible Solutions: Plasma, Raiden, State Sharding, IPFS, Private/Permissioned)

    Chains ▪ Description: Currently Ethereum only does a peak of 15 transactions per second. Visa on the other hand peaks 40,000 transactions per second Facebook does 175,000 transactions per second. If Ethereum is to be a “World computer” there’s is a lot of room for improvement.
  25. Privacy ▪ Possible Solutions: Zero Knowledge Proofs, Private chains ▪

    Description: Currently on Ethereum, a significant quantity is open to the general public. Thus making it unattractive for entities with sensitive data to deploy applications on Ethereum’s main net. There is also the pressing issue of proper privacy management tools.
  26. Contract bugs ▪ Possible Solutions: Forman Verification, Declarative Programming ▪

    Description: Smart contracts in are what I like to call “safe explosives”. Meaning the contracts you deploy are secure given the immutable properties of the Ethereum platform but Any mistake done is final & cannot be corrected. ▪ Victims: Parity $300 Million The DAO $50 Million The $32 million dollar multi-sig hack
  27. Further reading ▪ Formalizing and Securing Relationships on Public Networks

    By Nick Szabo http://firstmonday.org/article/view/548/469 ▪ Technical Explainer of bockchain concepts by Anders Brownworth https://anders.com/blockchain/hash.html https://anders.com/blockchain/block.html https://anders.com/blockchain/blockchain.html https://anders.com/blockchain/distributed.html https://anders.com/blockchain/tokens.html https://anders.com/blockchain/coinbase.html ▪ Ethereum White & Yellow Paper White Paper https://github.com/ethereum/wiki/wiki/White-Paper Yellow Paper http://gavwood.com/paper.pdf ▪ Official Documentation Of Vyper https://vyper.readthedocs.io/en/latest/