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

Programming the Web 3.0

Programming the Web 3.0

Introduction to ethereum and smart contracts



May 12, 2022

More Decks by Aletheia

Other Decks in Technology


  1. COURSE Blockchain Programming the Web 3.0

  2. NOME CLIENTE 11/05/22 Who am I? Luca Bianchi, PhD Chief

    Technology Officer @ Neosperience AWS Hero, passionate about serverless and machine learning github.com/aletheia https://it.linkedin.com/in/lucabianchipavia https://speakerdeck.com/aletheia www.ai4devs.io @bianchiluca
  3. Ethereum

  4. X Ethereum Forked from main BTC blockchain in 2014 by

    Vitalik Buterin. Eveolves Blockchain introducing Smart Contracts Contracts are deployed to Ethereum nodes and become part of the blockchain (every contract has an address) Contracts run are payed with gas (representing computational power) The unit of coin is called ether Once a transaction is added to the blockchain, the corresponding contract is executed Contracts can change ownership, ensure certification, etc.
  5. X Ether It is the native crypto currency used on

    Ethereum blockchain. Provides an economic incentive for participants to verify and execute transaction requests and provide computational resources to the network. Any participant who broadcasts a transaction request must also offer some amount of ether to the network as a bounty. It is a strong incentive to avoid malicious computations, such as the execution of infinite loops.
  6. X Gas and Fees Gas refers to the unit that

    measures the amount of computational effort required to execute specific operations on the Ethereum network. Since each Ethereum transaction requires computational resources to execute, each transaction requires a fee. Gas refers to the fee required to conduct a transaction on Ethereum successfully. Gas fees are paid in Ethereum’s native currency, ether (ETH). Gas prices are denoted in gwei. Each gwei is equal to 0.000000001 ETH
  7. X Ethereum Virtual Machine It is an abstraction layer modelling

    a computing machine, which state is stored on every node on the Blockchain Any participant can broadcast a request for this computer to perform arbitrary computation. Whenever such a request is broadcast, other participants on the network verify, validate, and carry out ("execute") the computation. This execution causes a state change in the EVM, which is committed and propagated throughout the entire network.
  8. None
  9. X Metamask Wallet Available as a browser extension and as

    a mobile app, MetaMask equips you with a key vault, secure login, token wallet, and token exchange—everything you need to manage your digital assets. MetaMask provides the simplest yet most secure way to connect to blockchain-based applications. You are always in control when interacting on the new decentralized web. MetaMask generates passwords and keys on your device, so only you have access to your accounts and data. You always choose what to share and what to keep private.
  10. X Testnets Networks used by protocol developers or smart contract

    developers to test both protocol upgrades as well as potential smart contracts in a production-like environment before deployment to Mainnet. Most testnets use a proof-of-authority consensus mechanism. This means a small number of nodes are chosen to validate transactions and create new blocks – staking their identity in the process. Most people get testnet ETH from faucet
  11. X EVM compatible blockchains • Binance Smart Chain (BSC) •

    Avalanche (AVAX) • Fantom (FTM)
  12. Smart Contracts

  13. X Intro to SC Smart contracts are simply programs stored

    on a blockchain that run when predetermined 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. Miners execute the actions when predetermined conditions have been met and verified (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
  14. X Solidity Solidity is an object-oriented, high-level language for implementing

    smart contracts. Smart contracts are programs which govern the behaviour of accounts within the Ethereum state. Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features. With Solidity you can create contracts for uses such as voting, crowdfunding, blind auctions, and multi-signature wallets.
  15. X Solidity A contract in the sense of Solidity is

    a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Since data is immutable on the blockchain, a variable is equivalent to a single slot in a database that can be queried and altered by calling contract functions.
  16. X Tools • Remix 
 Interactive web based IDE, to

    try smart contracts, useful for small PoCs • Truffle, Ganache 
 Getting started tools for beginners, with local blockchain, some form of automation. • Hardhat 
 A complete toolchain for production development with compiler, linting, local BC, deployment pipeline, and testing support • Forge and dApp Tools 
 Advanced tools to manage smart contract development and interact directly low level with blockchain virtual machine
  17. X Smart Contracts templates

  18. X Smart Contracts 
 Wizard https:// docs.openzeppelin.com/ contracts/4.x/wizard

  19. X Application Binary Interface (ABI) • The Contract Application Binary

    Interface (ABI) is the standard way to interact with contracts in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interaction. Data is encoded according to its type, as described in this specification. • EVM (Ethereum Virtual Machine) is the core component of the Ethereum network, and smart contract is pieces of code stored on the Ethereum blockchain which are executed on EVM. Smart contracts written in high-level languages like Solidity or Vyper need to be compiled in EVM executable bytecode.
  20. X Application Binary Interface (ABI) • Languages that compile for

    the EVM maintain strict conventions about these conversions, but in order to perform them, one must know the precise names and types associated with the operations. • The ABI documents these names and types precisely, easily parseable format, doing translations between human-intended method calls and smart-contract operations discoverable and reliable. • ABI defines the methods and structures used to interact with the binary contract, just like API does but on a lower-level.
  21. X dApp Work fl ow • Metamask offers standard layer

    of APIs to connect to a wallet • private keys are never shared, but transactions are routed through the wallet • metamask injects a window.ethereum variable • we need a frontend library to handle Metamask and Smart Contract APIs
  22. None
  23. ERC-20: fungible tokens

  24. X What is an ERC-20? • An ERC-20 token is

    a smart contract that has an established data structure. • ERC20 defines balanceOf , totalSupply , transfer , transferFrom , approve , and allowance and also name, symbol, and the number of decimals. • Any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them. • ERC20 tokens are useful for things like a medium of exchange currency, voting rights, staking,
  25. X What is an ERC-20?

  26. ERC-721: 
 non fungible tokens

  27. X What is an ERC-721? • Used in situations like

    real estate, voting rights, or collectibles, where some items are valued more than others, due to their usefulness, rarity, etc. • ERC721 is a standard for representing ownership of non-fungible tokens, that is, where each token is unique. • ERC721 is a more complex standard than ERC20, with multiple optional extensions, and is split across a number of contracts. • https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
  28. X What is an ERC-721?

  29. Challenges of the existing Blockchains

  30. X Scalability Blockchain scalability is capped by its redundancy, which

    ensures resiliency. The workflow is heavily impacted by Mining strategy: using PoW requires a lot of time for a block to be mined with state-of-the-art computational power, which slows down the chain Confirmation time (Finality): is the amount of time required to settle a block on the blockchains. Usally the information can be consolidated after a number of confirmations (miners confirming a block is valid). For BTC this time is 6 confirmations (~60 minutes) with ETH it is 25 confirmations (~ 6 minutes) Such figures get worse when the network grows in size.
  31. None
  32. X Cost Gas price has a lot of volatility and

    can reach peaks making transactions unfeasible
  33. X Security 51% attacks: During the verification process, individuals referred

    to as “miners” will review the transactions to ensure they are genuine. When one or more hackers gain control over half of the mining process, there can be extremely negative consequences. (i.e. Ronin Network) Creation errors: Sometimes, there may be security glitches or errors during creation of blockchain. This may be more common with larger, more intricate blockchains. One of the most hacked pieces of blockchain is not the chain itself, but the smart contracts involved in a dApp (i.e. Axie Infinity) Insufficient security: Many blockchain hacks have happened on exchanges, which is where users can trade cryptocurrecy (i.e. Quadriga) https://www.technologyreview.com/2022/04/15/1050259/a-620-million-hack-just-another-day-in-crypto/
  34. X Interoperability Blockchain interoperability allows data and value to be

    transferred across different networks. It has become an increasingly important feature of Web3. Interoperability allows for domain-specific blockchains to be developed, with business logic built into the foundation of the blockchain. But the capability to exchange data is fundamental when dealing with context-specific blockchains, to allow reliablity
  35. Ethereum 2.0, 
 L1 and L2

  36. X Strategies Different strategies to overcome scalability and cost issues:

    - adopt a new blockchain with different consensus protocols and improved communication. These are called layer 1 chains, because propose a new virtual machine - build on the EVM high abstraction layer 2 (and above) chains, leveraging Ethereum as the basis of the stack, but shifting computational load to faster consensus chains
  37. X Polkadot • Cross-blockchain transfers of any type of data

    or asset, not just tokens. • Proof-of-Authority (now) evolves into Nominated Proof-of-Stake (NPoS) 
 it is an enhanced mechanism where nominators back validators with their stake. Everyone could be a validator, but a nominator must select to back its efforts • Parachains • Rust language to write smart contracts
  38. X Solana • Focused on performances up to 1644 transactions

    per second (400ms block time) • Low cost transactions (~0.001$ each) • Solana’s Proof of Stake (PoS) based consensus method, termed Tower BFT, uses the network’s Proof of History (PoH) approach as a reminder before consensus. • Voting on a fork is limited to a defined period of hashes called a slot each time a validator votes on it. For one slot, the current network configuration is about 400 milliseconds (ms). • Rust language to write smart contracts
  39. X Binance Smart Chain • Proof-of-Authority (PoSA): participants stake BNB

    to become validators. f they propose a valid block, they’ll receive transaction fees from the transactions. • Given there are more than 1/2*N+1 validators are honest, PoA based networks usually work securely and properly. To secure as much as BC, BSC users are encouraged to wait until receiving blocks sealed by more than 2/3*N+1 different validators. Actually uses 21 validators which means ~5s to get a block and finality after 75s • EVM-compatible
  40. X Avalanche • PoS: the validators do not determine which

    blocks are valid. • 4500 transactions per second • Generic Classical consensus with probabilistic model • Immediate Finality: transactions are finalized immediatly in less than 1s • EVM-compatible
  41. X Fantom Opera Network • Leaderless PoS: the validators do

    not determine which blocks are valid. 
 Removing leaders increases network security substantially • Fast Finality: do not require a certain amount of time for transactions to be considered settled • EVM-compatible
  42. X L2: Polygon and Arbitrum Layer 2 (L2) is a

    collective term to describe a specific set of Ethereum scaling solutions. A layer 2 is a separate blockchain that extends Ethereum and inherits the security guarantees of Ethereum. Polygon 
 A complete solution of Ethereum-scaling tools to provide PoS, optimistic rollups, zk-rollup, and private networks Arbitrum 
 Transactions are managed by aggregators. An aggregator plays the same role that a node plays in Ethereum. The aggregator will then make calls to the EthBridge and produce transaction results to the client, just as an Ethereum node would.
  43. X Ethereum 2.0 Proof-of-Stake • With proof-of-stake (POS), cryptocurrency owners

    validate block transactions based on the number of coins a validator stakes. • Proof-of-stake (POS) was created as an alternative to Proof-of-work (POW), the original consensus mechanism used to validate a blockchain and add new blocks. • Proof-of-stake (POS) is seen as less risky in terms of the potential for an attack on the network, as it structures compensation in a way that makes an attack less advantageous. •
  44. X Ethereum 2.0 zk-rollup • ZK-Rollups are one of the

    options being developed for layer 2 construction that increases scalability through mass transfer processing rolled into a single transaction • A "zero knowledge proof" approach is used to present and publicly record the validity of the block on the Ethereum blockchain. ZK reduces computing and storage resources for validating the block by reducing the amount of data held in a transaction; zero knowledge of the entire data is needed. • Users on a dapp running the ZK-Rollup scheme will pay less in transaction fees.
  45. A real-life 

  46. X WizKey DeFiNe • Upload the documentation, Define your portfolio

    and sell it in a global market. • Improved portfolio management • Improved negotiation and transfer of credits • Access to a global market • Guaranteed security on transactions • High level of confidentiality www.wizkey.io/en
  47. Thank you! 25125 BRESCIA, VIA ORZINUOVI, 20 20137 MILANO, VIA