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

Blockchain - Ethereum - Tokens

Blockchain - Ethereum - Tokens

Blockchain Concepts
Ethereum Concept / Features
Ethereum Tokens ERC20
Ethereum Stack
Write Smart Contracts
Use Cases

Araf Karsh Hamid

June 05, 2022
Tweet

More Decks by Araf Karsh Hamid

Other Decks in Technology

Transcript

  1. @arafkarsh arafkarsh 8 Years Network & Security 6+ Years Microservices

    Blockchain 8 Years Cloud Computing 8 Years Distributed Computing Architecting & Building Apps a tech presentorial Combination of presentation & tutorial ARAF KARSH HAMID Co-Founder / CTO MetaMagic Global Inc., NJ, USA @arafkarsh arafkarsh 1 Blockchain Technology o WEB 1.0 / 2.0 / 3.0 o ETHEREUM CONCEPTS o ETHEREUM DEEP DIVE / TOKENS o ETHEREUM STACK o ETHEREUM DEMO Part 2 of 2
  2. @arafkarsh arafkarsh Slides are color coded based on the topic

    colors. Web 1.0 / 2.0 / 3.0 1 Ethereum Concepts Crypto Currency, Wallet, Dapps 2 Ethereum Deep Dive Accounts / Transactions Blocks / Gas / Tokens EVM / Nodes / Networks 3 Ethereum Setup MetaMask / Ganache Demo 4 2
  3. @arafkarsh arafkarsh Blockchain Properties Distributed Ledger No central authority controlling

    the system like Bank, Govt, Corporate Trust & Transparent Transactions are final and trusted via Consensus protocol Permanent Immutable Safe & Guaranteed storage and transfer of Digital Value Smart Contracts Executable Business Contracts IFTTT –Smart Contracts Guaranteed Execution IFTTT – If This Then That 4
  4. @arafkarsh arafkarsh Business Requirements Shared Ledger Append only immutable database

    shared across the business network. Business logic is embedded within the database and executed to validate and store the transactions. Smart Contract Transactions are secure, authenticated and access controls are enabled for granular access. Privacy Trust All the transactions are verified and endorsed by the trusted relevant parties 5
  5. @arafkarsh arafkarsh How Blockchain Works? 6 Client sends request Transaction

    is Broadcasted to Blockchain Cluster Transactions will be validated by any node in the network using Consensus Algorithms & Smart Contract Multiples Nodes in the Cluster will verify the transaction and after the verification the new block is added to the chain and replicated across all the nodes. Client request completed
  6. @arafkarsh arafkarsh Hyperledger Fabric Architecture 7 Orderer • Consensus verification

    • Creates Blocks CA • Registration of identities • Manage Certificates Peer • Endorses Tx • Simulates Tx • Commits Tx All these components can be clustered for scalability and to avoid Single Point of Failure 3 Components of Fabric Ledger Blockchain & World State Smart Contract • createCar • queryAllCars • queryCarProperties • changeCarColor • changeCarOwner Other Concepts • Endorsement Policies • Tokens • Assets : Anything that’s valuable for the Organization • Transactions (State changes of Assets) • Gossip Protocol : The glue that keeps the peers in healthy state. Channels • Private subnet for a set of parties based on Smart contract • Ledger / Channel • Peers can have multiple Channels • Private Data 1 2
  7. @arafkarsh arafkarsh 1 Web 1.0 / 2.0 / 3.0 o

    Evolution of Web 1.0, 2.0, 3.0 o Core Ideas of Web 3.0 8
  8. @arafkarsh arafkarsh Web Evolution Invented By Tim Berners Lee (CERN)

    in 1990s (1991-2004) HTTP: Hyper Text Transport Protocol HTML: Hyper Text Markup Language Browser 1. Text Based (Lynx Browser) 2. Mosaic Browser 3. Netscape 4. Internet Explorer Linking Documents across the world Read Only Web Web 1.0 Web 2.0 Linking Data Read / Write Web Technology 1. JavaScript 2. Flash 3. Active X 4. Java Web 3.0 Knowledge Read / Write Own Technology 1. Semantic Web 2. Blockchain 3. Crypto Currencies 4. Decentralized Apps 5. Wallets 9
  9. @arafkarsh arafkarsh Web 3.0 – Semantic Web Source: Sir Tim

    Berners Lee: Sematic Web: TedX 2009, GoTo 2018 W3C Semantic Web: https://www.w3.org/RDF/Metalog/docs/sw-easy Wisdom Knowledge Data / Info Documents Web 1.0 Web 2.0 Web 3.0 10
  10. @arafkarsh arafkarsh Core Ideas of Web 3.0 11 • Web3

    is decentralized: instead of large swathes of the internet controlled and owned by centralized entities, ownership gets distributed amongst its builders and users. • Web3 is permissionless: everyone has equal access to participate in Web3, and no one gets excluded. • Web3 has native payments: it uses cryptocurrency for spending and sending money online instead of relying on the outdated infrastructure of banks and payment processors. • Web3 is trustless: it operates using incentives and economic mechanisms instead of relying on trusted third-parties. Source: https://ethereum.org/en/web3/
  11. @arafkarsh arafkarsh Web 3.0 Blockchain based 12 Web2 Web3 Twitter

    can censor any account or tweet Web3 tweets would be uncensorable because control is decentralized Payment service may decide to not allow payments for certain types of work Web3 payment apps require no personal data and can't prevent payments Servers for gig-economy apps could go down and affect worker income Web3 servers can't go down – they use Ethereum, a decentralized network of 1000s of computers as their backend Source: https://ethereum.org/en/developers/docs/web2-vs-web3/
  12. @arafkarsh arafkarsh Web 3 Limitations 13 • Scalability – transactions

    are slower on web3 because they're decentralized. Changes to state, like a payment, need to be processed by a miner and propagated throughout the network. • UX – interacting with web3 applications can require extra steps, software, and education. This can be a hurdle to adoption. • Accessibility – the lack of integration in modern web browsers makes web3 less accessible to most users. • Cost – most successful dapps put very small portions of their code on the blockchain as it's expensive. Source: https://ethereum.org/en/developers/docs/web2-vs-web3/
  13. @arafkarsh arafkarsh Web Evolution Summary 14 Web 1.0: Read-Only (1990-2004)

    The first inception of Berners-Lee's creation, now known as 'Web 1.0', occurred roughly between 1990 to 2004. Web 1.0 was mainly static websites owned by companies, and there was close to zero interaction between users - individuals seldom produced content - leading to it being known as the read- only web. Source: https://ethereum.org/en/web3/ Web 2.0: Read-Write (2004-now) The emergence of social media platforms. Web evolved to be read- write. Companies also began to provide platforms to share user- generated content and engage in user- to-user interactions. Few companies began to control data and value generated on the web. While users could create content, they didn't own it or benefit from its monetization. Web 3.0: Read-Write-Own (2014-?) With the introduction of Blockchain in 2008, The premise of 'Web 3.0' was coined by Ethereum co-founder Gavin Wood in 2014. It’s a decentralized, permissionless, trustless and with a native payment system. Decentralized Centralized Decentralized
  14. @arafkarsh arafkarsh Ethereum Platform Features Source: https://ethereum.org/en/what-is-ethereum/ Banking for everyone

    Not everyone has access to financial services. But all you need to access Ethereum, and its lending, borrowing and savings products is an internet connection. A more private internet You don't need to provide all your personal details to use an Ethereum app. Ethereum is building an economy based on value, not surveillance. A peer-to-peer network Ethereum allows you to move money, or make agreements, directly with someone else. You don't need to go through intermediary companies. Censorship-resistant No government or company has control over Ethereum. This decentralization makes it nearly impossible for anyone to stop you from receiving payments or using services on Ethereum. Commerce guarantees Ethereum creates a more level playing field. Customers have a secure, built-in guarantee that funds will only change hands if you provide what was agreed. You don’t need large company clout to do business. Compatibility for the win Better products and experiences are being built all the time because Ethereum products are compatible by default. Companies can build on each other's success. 16
  15. @arafkarsh arafkarsh Key Concepts Source: https://ethereum.org/en/what-is-ethereum/ ETH Ethereum's native cryptocurrency

    and equivalent to Bitcoin. You can use ETH on Ethereum applications or for sending value to friends and family. Wallets How you manage your ETH and your Ethereum account. You'll need a wallet to get started. Ethereum Dapps Products and services that run on Ethereum. There are Dapps for finance, work, social media, gaming and more – meet the apps for our digital future. 17
  16. @arafkarsh arafkarsh Ethereum Use Cases Decentralized finance (DeFi) A more

    open financial system that gives you more control over your money and unlocks new possibilities. Non-fungible tokens (NFTs) A way to represent unique items as Ethereum assets that can be traded, used as proof of ownership, and create new opportunities for creators. Decentralized autonomous organisations (DAOs) A new way to collaborate and set up online communities with shared goals and pooled funds. Source: https://ethereum.org/en/what-is-ethereum/ 18
  17. @arafkarsh arafkarsh Eth – Crypto Currency Source: https://ethereum.org/en/eth/ Available in

    flexible amounts You can buy fractions of ETH. 0.000000000000000001 ETH if you want. (18th decimal place) Your Own Bank ETH lets you be your own bank. You can control your own funds with your wallet as proof of ownership – no third parties necessary. Eth is scarce digital money that you can use on the internet – similar to Bitcoin No centralized control ETH is decentralized and global. There's no company or bank that can decide to print more ETH or change the terms of use. Secured by cryptography It's secured by proven cryptography. This protects your wallet, your ETH, and your transactions. Peer-to-peer payments You can send your ETH without any intermediary service like a bank. It's like handing cash over in-person, but you can do it securely with anyone, anywhere, anytime. Open to anyone You only need an internet connection and a wallet to accept ETH. You don't need access to a bank account to accept payments. 20
  18. @arafkarsh arafkarsh Ethereum Wallet Source: https://ethereum.org/en/wallets/ Ethereum wallets are applications

    that let you interact with your Ethereum account, like an internet banking app – without the bank. You need a wallet to manage your ETH. Your wallet lets you read your balance, send transactions and connect to applications. 1. Your wallet is only a tool for managing your Ethereum account. 2. That means you can swap wallet providers at any time. 3. Many wallets also let you manage several Ethereum accounts from one App. 4. That's because wallets don't have custody of your funds, you do. 5. They're just a tool for managing what's really yours. 21
  19. @arafkarsh arafkarsh Ethereum Wallet Source: https://ethereum.org/en/wallets/ Your Ethereum account Your

    wallet is your window into your Ethereum account – your balance, transaction history and more. But you can swap wallet providers at any time. Your login for Ethereum apps Your wallet lets you connect to any decentralized application using your Ethereum account. It's like a login you can use across many Dapps. An app for managing your funds Your wallet shows your balances, transaction history and gives you a way to send/receive funds. Some wallets may offer more. 22
  20. @arafkarsh arafkarsh Accounts / Addresses / Wallet A Wallet is

    a product that lets you manage your Ethereum account. To view your account balance, send transactions, and more. An Ethereum Account is an entity that can send transactions and has a balance. Source: https://ethereum.org/en/wallets/ Ethereum Address, like an email address for your account. 23
  21. @arafkarsh arafkarsh Types of Wallet Physical hardware wallets that let

    you keep your crypto offline – very secure Source: https://ethereum.org/en/wallets/ Mobile applications that make your funds accessible from anywhere. Web wallets that let you interact with your account via a web browser. Desktop Apps to manage your funds via macOS, Windows or Linux. 24
  22. @arafkarsh arafkarsh Decentralized Apps Decentralized - Dapps operate on Ethereum,

    an open public decentralized platform where no one person or group has control Source: https://ethereum.org/en/developers/docs/dapps/ Deterministic - Dapps perform the same function irrespective of the environment in which they get executed Turing complete - Dapps can perform any action given the required resources Isolated - Dapps are executed in a virtual environment known as Ethereum Virtual Machine so that if the smart contract has a bug, it won’t hamper the normal functioning of the blockchain network 25
  23. @arafkarsh arafkarsh Dapps Benefits No owners Once deployed to Ethereum,

    dapp code can’t be taken down. And anyone can use the Dapp’s features. Even if the team behind the Dapp disbanded you could still use it. Once on Ethereum, it stays there. Dapps might feel like regular apps. But behind the scenes they have some special qualities because they inherit all of Ethereum’s superpowers. Source: https://ethereum.org/en/dapps/#what-are-dapps One Anonymous Login No Down time Secured Cryptographically Built-In Payments No Censorship Plug and Play 26
  24. @arafkarsh arafkarsh Dapps Drawbacks Maintenance • Code and data published

    to the blockchain are harder to modify. • It’s hard for developers to make updates to their once they are deployed, even if bugs or security risks are identified in an old version. Source: https://ethereum.org/en/developers/docs/dapps/ Performance overhead • There is a huge performance overhead, and scaling is really hard. To achieve the level of security, integrity, transparency, and reliability that Ethereum aspires to, • Every node runs and stores every transaction. • Proof-of-work takes time as well (1,000,000x that of standard computation currently). Network congestion • When one dapp uses too many computational resources, the entire network gets backed up. • the network can only process about 10-15 transactions per second Centralization • Solutions built on top of the base layer of Ethereum might end up looking like centralized services anyways. • Centralization eliminates many (if not all) of the advantages of blockchain over the traditional model. User experience • Too difficult to set up a tool stack necessary to interact with the blockchain in a truly secure fashion. 27
  25. @arafkarsh arafkarsh Smart Contracts Source: https://ethereum.org/en/developers/docs/smart-contracts/ It is simply a

    program that runs on the Ethereum blockchain. It's a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Smart contracts are a type of Ethereum account. This means they have a balance, and they can send transactions over the network. However, they're not controlled by a user, instead they are deployed to the network and run as programmed. Permissionless Anyone can write a smart contract and deploy it to the network. You just need enough ETH to deploy your contract. Deploying a smart contract is technically a transaction. Gas costs for contract deployment are far higher, however. 28
  26. @arafkarsh arafkarsh Smart Contracts Source: https://ethereum.org/en/developers/docs/smart-contracts/ Compossibility Smart contracts are

    public on Ethereum and can be thought of as open APIs. That means you can call other smart contracts in your own smart contract to greatly extend what's possible. Contracts can even deploy other contracts. Multiple Signature Contracts Multisig (multiple-signature) contracts are smart contract accounts that require multiple valid signatures to execute a transaction. This is very useful for avoiding single points of failure for contracts holding substantial amounts of ether or other tokens (if the signature key is lost). Limitations They can't send HTTP requests by design for security reasons. (Use Oracles) A smart contract can be a maximum of 24 KB, or it will run out of gas. Diamond Pattern to overcome this issue. 29
  27. @arafkarsh arafkarsh Oracle Source: https://ethereum.org/en/developers/docs/oracles/ Oracles are data feeds that

    connect Ethereum to off-chain, real-world information so that you can query data in your smart contracts. An oracle is a bridge between the blockchain and the real world. They act as on-chain APIs you can query to get information into your smart contracts. Why do we need an Oracle? With a blockchain like Ethereum, you need every node in the network to replay every transaction and end up with the same result, guaranteed. APIs introduce potentially variable data. If you were sending ETH based on an agreed $USD value using a price API, the query would return a different result from one day to the next. Not to mention, the API could be hacked or deprecated. 30
  28. @arafkarsh arafkarsh 3 Ethereum Deep Dive o Accounts / Transactions

    / Blocks o Gas o Ethereum Virtual Machine 31 o Nodes & Clients o Networks o Consensus Mechanism
  29. @arafkarsh arafkarsh Merkle Tree Source: Ralph Merkle: 1987 A Digital

    Signature Based on a Conventional Encryption Function H (D1) H (D2) H (D3) H (D4) Hash 1 = D1+D2 Hash 2 = D3+D4 Hash Root = H1+ H2 H (D1) H (D2) H (D3) H (D4) Hash 1 = D1+D2 Hash 2 = D3+D4 Hash Root (HR) = H1+ H2 Data 3 To Verify Data 3 HR, H1 & D4 received from Trusted System 1. Compute D3 Hash 2. Compute H2 with D3 + D4 3. Compute new HR with H1 + H2 4. Compare HR with new HR Verify Data 3 32
  30. @arafkarsh arafkarsh Accounts 34 An Ethereum account is an Entity

    with an ether (ETH) balance that can send transactions on Ethereum. Source: https://ethereum.org/en/developers/docs/accounts/ 1. Externally-owned – controlled by anyone with the private keys 2. Contract – a smart contract deployed to the network, controlled by code. Account types: EVM Code Storage Autonomous Object Externally Owned Account (EOA) Contract Account World State EOA is Controlled by a Private Key Contract Account contains EVM Code
  31. @arafkarsh arafkarsh Accounts 35 Source: https://ethereum.org/en/developers/docs/accounts/ Key differences Externally-owned 1.

    Creating an account costs nothing 2. Can initiate transactions 3. Transactions between externally-owned accounts can only be ETH/token transfers Both account types have the ability to: 1. Receive, hold and send ETH and tokens 2. Interact with deployed smart contracts Contract 1. Creating a contract has a cost because you're using network storage 2. Can only send transactions in response to receiving a transaction 3. Transactions from an external account to a contract account can trigger code which can execute many different actions, such as transferring tokens or even creating a new contract.
  32. @arafkarsh arafkarsh Accounts & Transactions 36 Externally Owned Account Contract

    Account Contract Account Internal Transaction Fired in response to the Tx initiated by an EOA Tx (Transactions) initiated by the Externally Owned Account (EOA) Transaction Externally Owned Account Transaction Externally Owned Account Externally Owned Account Externally Owned Account Externally Owned Account Source: https://www.preethikasireddy.com/post/how-does-ethereum-work-anyway Ethereum Blockchain All the transactions in the Blockchain is triggered by an EOA
  33. @arafkarsh arafkarsh Accounts & World State 37 World State Account

    1 State Address 1 Account 2 State Address 2 Account 3 State Address 3 World State Account 1 Account 2 Account 3 Account is an Object in the world State Account is a mapping between Address & Account State
  34. @arafkarsh arafkarsh Account State 38 Source: https://ethereum.org/en/developers/docs/accounts/ Fields Externally Owned

    Account Contract Account nonce Number of Tx send from Accounts Address Number of Contracts Created by the Account balance Number of Wei owned by this Account storageRoot 256-bit Hash of the Root Node of a Merkle Tree codeHash Hash of Empty String Hash of the Code that's stored Externally Owned Account An Account is made up Cryptographic pair of keys: Private & Public Keys • Private Key is used to Sign the Transactions. • Funds are always on Ethereum’s Ledger • An Account is NOT a Wallet
  35. @arafkarsh arafkarsh Account State 39 EVM Code Storage Autonomous Object

    Externally Owned Account (EOA) Contract Account World State Contract is controlled by EVM Code Contract Account contains EVM Code EOA is Controlled by a Private Key EOA cannot contain EVM Code nonce balance Storage Hash Code Hash Account State Address nonce balance Storage Hash Code Hash Account State Address
  36. @arafkarsh arafkarsh Blocks 41 Source: https://ethereum.org/en/developers/docs/blocks/ World State t Transaction

    T1 Transaction T2 Transaction T3 World State t+1 Block b Transactions are grouped into a block o Blocks are batches of transactions with a hash of the previous block in the chain. o This links blocks together (in a chain) because hashes are cryptographically derived from the block data. o This prevents fraud, because one change in any block in history would invalidate all the following blocks as all subsequent hashes would change and everyone running the blockchain would notice. To ensure that all participants on the Ethereum network maintain a synchronized state and agree on the precise history of transactions, batch transactions into blocks. This means dozens (or hundreds) of transactions are committed, agreed on, and synchronized on all at once.
  37. @arafkarsh arafkarsh Anatomy of a Block 42 # Field Description

    1 Time Stamp The time when the block was mined. 2 Block Number The length of the Blockchain in the Blocks 3 Base Fee Per Gas The Minimum Fee Per Gas required for a transaction to be included in the Block 4 Difficulty The effort required to mine the Block 5 Mix Hash A Unique Identifier for that Block 6 Parent Hash The Unique identifier for the block that came before this Block. 7 Transactions The Transactions included in the Block 8 State Root The Entire State of the System; Account Balances, Contract Storage, Contract Code, and Account Nonce are inside. 9 Nonce A Hash that, when combined with the Mix Hash, proves that the block has gone through. Source: https://ethereum.org/en/developers/docs/blocks/
  38. @arafkarsh arafkarsh Block Time & Size 43 • Block time

    refers to the time it takes to mine a new block. Average is 12-14 Seconds. • The average block time gets compared with the expected block time, and if the average block time is higher, then the difficulty is decreased in the block header. • If the average block time is smaller, then the difficulty in the block header will be increased. Block Time Source: https://ethereum.org/en/developers/docs/blocks/ • A final important note is that blocks themselves are bounded in size. • Each block has a target size of 15 million gas. • The size of blocks will increase or decrease in accordance with network demands, up until the block limit of 30 million gas (2x target block size). • The total amount of gas expended by all transactions in the block must be less than the block gas limit. Block Size
  39. @arafkarsh arafkarsh Transaction 44 External Actor A Person or an

    Entity Transaction Ethereum World World State A transaction is submitted by the External Actor 2 Types of Transactions, Contract Creation / Message Call External Actor Contract Creation Transaction Create World State Contract Account External Actor Message Call Transaction Message World State EOA EOA / CA
  40. @arafkarsh arafkarsh Transactions 45 Source: https://ethereum.org/en/developers/docs/transactions/ Transactions are cryptographically signed

    instructions from accounts. An account will initiate a transaction to update the state of the Ethereum network. The simplest transaction is transferring ETH from one account to another. An Ethereum transaction refers to an action initiated by an externally-owned account, in other words an account managed by a human, not a contract. Transactions, which change the state of the EVM, need to be broadcast to the whole network. Any node can broadcast a request for a transaction to be executed on the EVM. A miner will execute the transaction and propagate the resulting state change to the rest of the network. Transactions require a fee and must be mined to become valid.
  41. @arafkarsh arafkarsh Transaction Structure 46 Source: https://ethereum.org/en/developers/docs/transactions/ Recipient The Receiving

    Address • Externally Owned Account: Transaction will transfer value. • Contract Account: Transaction will execute the Contract Code. Signature The Identifier of the Sender • Senders Private Key is used to sign the Transaction & confirms the Sender has authorized this transaction. Value Amount of ETH to transfer from Sender to Recipient (in Wei, a denomination of ETH). Data Optional Field to include arbitrary data Gas Limit Max Amount of Gas Units that can be consumed by the Transaction. Max Fee Per Gas Max Amount of Gas willing to be paid for the transaction (inclusive of Base Fee Per Gas and Max Priority Fee Per Gas) Max Priority Fee Per Gas Max Amount of Gas to be included as a tip to the miner.
  42. @arafkarsh arafkarsh Transaction Data 47 Source: https://ethereum.org/en/developers/docs/transactions/ Gas is a

    reference to the computation required to process the transaction by a miner. Users have to pay a fee for this computation. The gasLimit, and maxPriorityFeePerGas determine the maximum transaction fee paid to the miner. Structure of the Transaction Object A transaction object needs to be signed using the sender's private key
  43. @arafkarsh arafkarsh Transaction based State Machine 48 Source: https://ethereum.org/en/developers/docs/transactions/ World

    State t World State t+2 Transaction T1 Transaction T2 Transaction T3 Block b Transactions are grouped into a block World State t+1 Transaction T4 Transaction T5 Transaction T6 Block b+2 From the viewpoint of the states, Ethereum can be seen as a state chain. From the viewpoint of the implementation, Ethereum can also be seen as a chain of blocks, so it is `BLOCKCHAIN`
  44. @arafkarsh arafkarsh What is Gas? 50 Source: https://ethereum.org/en/developers/docs/gas/ 1. Gas

    refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network. 2. Since each Ethereum transaction requires computational resources to execute, each transaction requires a fee. 3. Gas refers to the fee required to conduct a transaction on Ethereum successfully. 4. Gas fees are paid in Ethereum's native currency, ether (ETH). 5. Gas prices are denoted in gwei, which itself is a denomination of ETH and each gwei = 10-9 ETH (gwei = giga-wei). 6. Gas fees help keep the Ethereum network secure. 7. By requiring a fee for every computation executed on the network, we prevent bad actors from spamming the network. 8. In order to avoid accidental or hostile infinite loops or other computational wastage in code, each transaction is required to set a limit to how many computational steps of code execution it can use.
  45. @arafkarsh arafkarsh Why there is Gas Limit? 51 Source: https://ethereum.org/en/developers/docs/gas/

    • Gas limit refers to the maximum amount of gas you are willing to consume on a transaction. • A standard ETH transfer requires a gas limit of 21,000 units of gas. • For example, if you put a gas limit of 50,000 for a simple ETH transfer, the EVM would consume 21,000, and you would get back the remaining 29,000. • However, if you specify too little gas, for example, a gas limit of 20,000 for a simple ETH transfer, the EVM will consume your 20,000 gas units attempting to fulfil the transaction, but it will not complete. The EVM then reverts any changes, but since the miner has already done 20k gas units worth of work, that gas is consumed. • High gas fees are due to the popularity of Ethereum. Performing any operation on Ethereum requires consuming gas, and gas space is limited per block.
  46. @arafkarsh arafkarsh Gas Calculation – Before London Upgrade 52 Source:

    https://ethereum.org/en/developers/docs/gas/ Alice had to pay Bob 1 ETH. Total Fee = 21,000 * 200 = 4,200,000 gwei or 0.0042 ETH Total fee = Gas units (limit) * Gas price per unit Gas limit = 21,000 units Gas price = 200 gwei • Alice sent the money = 1.0042 ETH • 1.0042 ETH deducted from Alice's account. • Bob would be credited 1.0000 ETH. • Miner would receive 0.0042 ETH.
  47. @arafkarsh arafkarsh Gas Calculation – After London Upgrade 53 Source:

    https://ethereum.org/en/developers/docs/gas/ Alice had to pay Bob 1 ETH. Cost = Base Fee + Tip = 100 gwei + 10 gwei Total Fee = 21,000 * 110 = 2,310,000 gwei or 0.00231 ETH Total fee = Gas units (limit) * (Base fee + Tip) Gas limit = 21,000 units Base Fee = 100 gwei Tip = User Defined • Alice sent the money = 1.00231 ETH • 1.00231 ETH deducted from Alice's account. • Bob would be credited 1.0000 ETH. • Miner would receive 0.00021 ETH. • Base Fee = 0.0021 ETH is burned
  48. @arafkarsh arafkarsh Block Size 54 Source: https://ethereum.org/en/developers/docs/gas/ • Before the

    London Upgrade, Ethereum had fixed-sized blocks. • In times of high network demand, these blocks operated at total capacity. • As a result, users often had to wait for high demand to reduce to get included in a block, which led to a poor user experience. • The London Upgrade introduced variable-size blocks to Ethereum. • Each block has a target size of 15 million gas, but the size of blocks will increase or decrease in accordance with network demand, up until the block limit of 30 million gas (2x the target block size). • The protocol achieves an equilibrium block size of 15 million on average through the process of tâtonnement. • This means if the block size is greater than the target block size, the protocol will increase the base fee for the following block. Similarly, the protocol will decrease the base fee if the block size is less than the target block size.
  49. @arafkarsh arafkarsh Base Fee 55 Source: https://ethereum.org/en/developers/docs/gas/ • Every block

    has a base fee which acts as a reserve price. • To be eligible for inclusion in a block the offered price per gas must at least equal the base fee. • The base fee is calculated independently of the current block and is instead determined by the blocks before it - making transaction fees more predictable for users. Block Number Included Gas Fee Increase Current Base Fee 1 15M 0% 100 gwei 2 30M 0% 100 gwei 3 30M 12.5% 112.5 gwei 4 30M 12.5% 126.6 gwei 5 30M 12.5% 142.4 gwei 6 30M 12.5% 160.2 gwei 7 30M 12.5% 180.2 gwei 8 30M 12.5% 202.7 gwei • When the block is mined this base fee is "burned", removing it from circulation. • Relative to the pre-London gas auction market, this transaction- fee-mechanism change causes fee prediction to be more reliable.
  50. @arafkarsh arafkarsh Priority Fee (Tips) 56 Source: https://ethereum.org/en/developers/docs/gas/ • Before

    the London Upgrade, miners would receive the total gas fee from any transaction included in a block. • With the new base fee getting burned, the London Upgrade introduced a priority fee (tip) to incentivize miners to include a transaction in the block. • Without tips, miners would find it economically viable to mine empty blocks, as they would receive the same block reward. • Under normal conditions, a small tip provides miners a minimal incentive to include a transaction. • For transactions that need to get preferentially executed ahead of other transactions in the same block, a higher tip will be necessary to attempt to outbid competing transactions.
  51. @arafkarsh arafkarsh Ethereum Virtual Machine 58 Source: https://ethereum.org/en/developers/docs/evm/ • The

    EVM’s physical instantiation can’t be described in the same way that one might point to a cloud or an ocean wave, but it does exist as one single entity maintained by thousands of connected computers running an Ethereum client. • The Ethereum protocol itself exists solely for the purpose of keeping the continuous, uninterrupted, and immutable operation of this special state machine; It's the environment in which all Ethereum accounts and smart contracts live. • At any given block in the chain, Ethereum has one and only one 'canonical' state, and the EVM is what defines the rules for computing a new valid state from block to block.
  52. @arafkarsh arafkarsh Nodes & Clients 59 Source: https://ethereum.org/en/developers/docs/nodes-and-clients/ • Ethereum

    is a distributed network of computers running software (known as nodes) that can verify blocks and transaction data. • You need an application, known as a client, on your computer to "run" a node. • Clients can run 3 different types of node - light, full and archive. Full node • Stores full blockchain data (although this is periodically pruned so a full node does not store all state data back to genesis) • Participates in block validation, verifies all blocks and states. • All states can be derived from a full node (although very old states are reconstructed from requests made to archive nodes). • Serves the network and provides data on request. Light node • Instead of downloading every block, light nodes download block headers. • These headers only contain summary information about the contents of the blocks. • Any other information required by the light node gets requested from a full node. • The light nodes do not participate in consensus (i.e. they cannot be miners/validators) Archive node • Stores everything kept in the full node and builds an archive of historical states.
  53. @arafkarsh arafkarsh Networks 60 Source: https://ethereum.org/en/developers/docs/networks/ • Since Ethereum is

    a protocol, this means there can be multiple independent "networks" conforming to this protocol that do not interact with each other. • Networks are different Ethereum environments you can access for development, testing, or production use cases. Your Ethereum account will work across the different networks but your account balance and transaction history won't carry over from the main Ethereum network. • Public networks are accessible to anyone in the world with an internet connection. Anyone can read or create transactions on a public blockchain and validate the transactions being executed. Agreement on transactions and the state of the network is decided by a consensus of peers. Ethereum Mainnet Mainnet is the primary public Ethereum production blockchain, where actual-value transactions occur on the distributed ledger.
  54. @arafkarsh arafkarsh Summary – Why do we need Blockchain? 61

    Reconciliation Issues in a Multi Party environment. o Expensive o Vulnerable o Inefficient Problem Statement o Consensus among the Parties before a transaction is committed. o Provenance – Origin of the asset can be easily Tracked. o Immutable – Transactions are tamper proof o Finality – Single Source of Truth Solution
  55. @arafkarsh arafkarsh Summary – Benefits of Blockchain Technologies Saves Time

    Immutable transaction across parties done at the same time. Remove Cost Overheads on maintaining and synchronizing silos. Increases Trust Through shared process and unified Systems of Record. For end consumers it’s a System of Proof. Reduces Risk Tampering of data, fraud and cyber crime is avoided. 62
  56. @arafkarsh arafkarsh Ethereum Vs. HyperLedger Fabric Vs. R3 Corda 63

    Characteristics Ethereum HyperLedger Fabric R3 Corda Description of the Platform Generic Blockchain Platform Modular Blockchain Platform Specialized distributed ledger platform for Financial Industry Release History December 2021 v2.2.5 January 28, 2022 v4.8 April 21, 2021 Crypto Currency Ether / Tokens (Usage, Work) via Smart Contract None Currency and Tokens via Chaincode None Governance Ethereum Developers Enterprise Ethereum Alliance Linux Foundation IBM R3 Consensus Mining based on Proof of Work (POW) – All participants need to agree. Ledger Level Selective Endorsement. Consensus can be even within a channel with select parties instead of everyone. Transaction Level Specific understanding of Consensus. (Validity, Uniqueness) Transaction Level Network Permissionless, Public or Private Permissioned, Private Permissioned, Private State Account Data Key-value Database Transaction Log, World State Vault contains States Historic & Current State Smart Contracts Solidity Chaincode (GoLang, Node.JS, Java) Smart Contract (Kotlin, Java) Development Languages GoLang, C++, Python Java, Node.JS, Python (Post 1.0) Java, Kotlin
  57. @arafkarsh arafkarsh What is an Ethereum Token 65 Tokens can

    represent virtually anything in Ethereum: • reputation points in an online platform • skills of a character in a game • lottery tickets • financial assets like a share in a company • a fiat currency like USD • an ounce of gold • and more... Source: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
  58. @arafkarsh arafkarsh Smart Contract & Tokens 67 Smart Contract o

    Create Tokens o Manages Transactions o Keeping Track of the Balances Tokens
  59. @arafkarsh arafkarsh Create Tokens 68 Send Ether to Smart Contract

    to Create Tokens Smart Contract Creates a Set of Tokens based on the Ether received Smart Contract
  60. @arafkarsh arafkarsh Standards and Exchanges 69 Exchanges Support Different Smart

    Contracts Based on Standards like ERC20 / ERC777 etc Token Exchange
  61. @arafkarsh arafkarsh Standards and Wallet Providers 70 Wallet Providers Support

    Different Smart Contracts Based on Standards like ERC20 / ERC777 etc Wallet Providers
  62. @arafkarsh arafkarsh ERC20 Standard 71 Ethereum Request for Comments 20

    Optional o Name = “Kat-Token” o Symbol = “KAT” o Decimal = 8 The ERC-20 introduces a standard for Fungible Tokens, in other words, they have a property that makes each Token be exactly the same (in type and value) as another Token Source: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
  63. @arafkarsh arafkarsh ERC20 Standard 72 Ethereum Request for Comments 20

    Mandatory o Total Supply o Balance Of o Transfer o Transfer From o Approve o Allowance The ERC-20 introduces a standard for Fungible Tokens, in other words, they have a property that makes each Token be exactly the same (in type and value) as another Token Source: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
  64. @arafkarsh arafkarsh ERC777 74 Source: https://ethereum.org/en/developers/docs/standards/tokens/erc-777/ Hooks Hooks are a

    function described in the code of a smart contract. Hooks get called when tokens are sent or received through the contract. This allows a smart contract to react to incoming or outgoing tokens. The hooks are registered and discovered using the ERC-1820 standard. 1. Hooks allow sending tokens to a contract and notifying the contract in a single transaction, unlike ERC-20, which requires a double call (approve/transferFrom) to achieve this. 2. Contracts that have not registered hooks are incompatible with ERC-777. The sending contract will abort the transaction when the receiving contract has not registered a hook. This prevents accidental transfers to non-ERC-777 smart contracts. 3. Hooks can reject transactions.
  65. @arafkarsh arafkarsh Ethereum Stack 76 Source: https://ethereum.org/en/developers/docs/ethereum-stack/ Ethereum Virtual Machine

    (EVM) is the runtime environment for smart contracts in Ethereum. All smart contracts and state changes on the Ethereum blockchain are executed by transactions. The EVM handles all of the transaction processing on the Ethereum network. Smart contracts are the executable programs that run on the Ethereum blockchain. Smart contracts are written using specific programming languages that compile to EVM bytecode (low-level machine instructions called opcodes). 1 2 4 3 In order for an application to interact with the Ethereum blockchain, it must connect to an Ethereum node. Connecting to a node allows you to read blockchain data and/or send transactions to the network.. Client API - If your user-facing application is a web app, you may choose to npm install a JavaScript API directly in your frontend. Or perhaps you'll choose to implement this functionality server-side, using a Python or Java API.
  66. @arafkarsh arafkarsh Smart Contract – Solidity 98 • Object-oriented, high-level

    language for implementing smart contracts. • Curly-bracket language that has been most profoundly influenced by C++. • Statically typed (the type of a variable is known at compile time). • Supports: • Inheritance (you can extend other contracts). • Libraries (you can create reusable code that you can call from different contracts – like static functions in a static class in other object oriented programming languages). • Complex user-defined types. Source: https://ethereum.org/en/developers/docs/smart-contracts/languages/
  67. @arafkarsh arafkarsh Storage vs Memory in Solidity 99 • Storage

    and Memory keywords in Solidity are analogous to Computer’s hard drive and Computer’s RAM. • Much like RAM, Memory in Solidity is a temporary place to store data whereas Storage holds data between function calls. • The Solidity Smart Contract can use any amount of memory during the execution but once the execution stops, the Memory is completely wiped off for the next execution. • Whereas Storage on the other hand is persistent, each execution of the Smart contract has access to the data previously stored on the storage area. • The Gas consumption of Memory is not very significant as compared to the gas consumption of Storage. Source: https://www.geeksforgeeks.org/storage-vs-memory-in-solidity/ 1. State variables and Local Variables of structs, array are always stored in storage by default. 2. Function arguments are in memory. 3. Whenever a new instance of an array is created using the keyword ‘memory’, a new copy of that variable is created. Changing the array value of the new instance does not affect the original array.
  68. @arafkarsh arafkarsh Setting up Visual Studio Code – Truffle 104

    mkdir project-name $ npm init -y $ npm install --save-dev @openzeppelin/contracts $ cd project-name $ npx truffle init $ npm install --save- dev truffle $ npx truffle compile $ Compile Install Open Zeppelin Smart Contracts Framework Install Truffle and initialize the project with Truffle (Sets the Solidity Config) Install npm and setup the Project (Create Directory and Initialize it) Write Smart Contract in Visual Studio Code Source: https://docs.openzeppelin.com/learn/developing-smart-contracts
  69. @arafkarsh arafkarsh Setting up Visual Studio Code – Run the

    Code 105 npm install --save-dev ganache- cli $ npx ganache-cli --deterministic $ Install Ganache Test Network Source: https://docs.openzeppelin.com/learn/deploying-and-interacting npx truffle migrate --network development $ npx truffle exec --network development ./scripts/index.js $
  70. @arafkarsh arafkarsh Setting up Visual Studio Code – Testing 106

    npm install --save-dev chai $ Setup Testing Framework Source: https://docs.openzeppelin.com/learn/writing-automated-tests npx truffle test $ Run the Test Cases
  71. @arafkarsh arafkarsh Blockchain Use Cases 108 1. High Value goods

    tracking 2. Logistics and Supply 3. Asset Management & Tracking 4. Chain of Custody Tracking 5. Anti Counterfeiting Supply Chain 1. Patient Data Management 2. Clinical Trials 3. Medical Devices Management 4. Pharmaceutical Tracking 5. Patient Data Exchange Health Care 1. Equity Trading 2. Know your Customer 3. Peer to Peer Lending 4. Derivatives Trading 5. Escrow Finance 1. Voting 2. Vehicle Registration 3. Land Registration 4. Copyrights 5. Immigration Management Government 1. Peer To Peer Insurance 2. Automated Insurance Claim 3. Car Insurance 4. Health Insurance 5. Fraud Detection Insurance 1. Remittance 2. Micro Finance 3. Identify Verification 4. Cross Border Payments 5. Hedge Funds Payments
  72. @arafkarsh arafkarsh Blockchain Use Cases 109 1. Farmers Loan Process

    2. Smart Farming 3. Fair Pricing 4. Reduce Food Waste 5. Animal Health & Food Safety Agriculture 1. Autonomous Vehicle 2. Health & Fitness 3. Device to Device Payment 4. Shipping & Logistics 5. Asset Management IoT 1. Royalty Payments 2. Content Bypassing Aggregator 3. Pricing for Paid Content 4. Ad Networks & Exchanges 5. Media Buying Media 1. Real Estate 2. Tourism 3. Energy Trading 4. Gaming 5. Identity General
  73. @arafkarsh arafkarsh Content Bypassing the AggregatorsSource: Deloitte : Blockchain @

    Media Content Producer / Artist Aggregator Consumer Current Scenario Content Producer / Artist Distributed Ledger Consumer After Introduction of Blockchain Benefits • Direct Customer Artist relationship. • Easy to measure marketing and performance. Challenges • Content Aggregators and Advertising networks to loose their dominant position. • Blockchain has the potential to make DRM systems obsolete or at least to reduce it’s complexity 110
  74. @arafkarsh arafkarsh Distribution of Royalty Payments Artist Aggregator User Current

    Scenario Music Publisher Distributor Artist User After Introduction of Blockchain Distributed Ledger Distributor Source: Deloitte : Blockchain @ Media Benefits • Near Real-time distribution of Royalty payments based on Smart Contracts • Every usage and consumption is tracked in Blockchain Challenges • Handling large amount of Data • All the parties agreeing to common Blockchain Platform. 111
  75. @arafkarsh arafkarsh Land Records Specs For any kind of a

    high value property (real estate, cars, art) it is important to have accurate records which identify the current owner and provide a proof that he is indeed the owner. These records can be used to • Protect owners' rights (e.g. in case of theft) • Resolve disputes • Make sure ownership is correctly transferred to a new owner after sale • Prevent sale fraud Source: https://chromaway.com/papers/A-blockchain-based-property-registry.pdf 112
  76. @arafkarsh arafkarsh Land Registration District 1 District n Bank Buyer

    Seller Property Tax Dept • Buyers and Seller are Cryptographically identified. • Ledger is distributed across all the districts in the state to ensure that forging the record is extremely difficult. Blockchain Ledger A shared, replicated, permissioned ledger 113
  77. @arafkarsh arafkarsh 114 DREAM | AUTOMATE | EMPOWER Araf Karsh

    Hamid : India: +91.999.545.8627 http://www.slideshare.net/arafkarsh https://www.linkedin.com/in/arafkarsh/ https://www.youtube.com/user/arafkarsh/playlists http://www.arafkarsh.com/ @arafkarsh arafkarsh
  78. @arafkarsh arafkarsh References - Blockchain Video Tutorials • https://www.ibm.com/topics/what-is-blockchain •

    https://www.geeksforgeeks.org/features-of-blockchain/ • https://101blockchains.com/introduction-to-blockchain-features/ • Blockchain Use Cases: https://wiki.hyperledger.org/groups/requirements/use-case-inventory • Hyperledger Fabric Explainer: https://www.youtube.com/watch?v=js3Zjxbo8TM • Blockchain Technology : https://www.youtube.com/watch?v=qOVAbKKSH10 • Smart Contracts : https://www.youtube.com/watch?v=ZE2HxTmxfrI • Hyperledger Fabric v1.1 Node.JS Chaincode : https://www.youtube.com/watch?v=dzwR0dwzXNs • Hyperledger Fabric v1.0 : https://www.youtube.com/watch?v=6nGIptzBZis • Hyperledger Fabric for Beginners : https://www.youtube.com/watch?v=Y177TCUc4g0 • Fabric Composer : https://www.youtube.com/watch?v=fdFUsrsv5iw • Hyperledger Composer : https://www.youtube.com/watch?v=iRlm4uY_9pA • How does it works: Blockchain : https://www.youtube.com/watch?v=lD9KAnkZUjU • How does Blockchain work: https://www.youtube.com/watch?v=LZEHOlZY2To • 19 Industries The Blockchain will disrupt : https://www.youtube.com/watch?v=G3psxs3gyf8 • What is the difference between Bitcoin & Blockchain? : https://www.youtube.com/watch?v=MKwa-BqnJDg • Bitcoin: What Bill Gates, Buffet, Elon Mush & Richard Branson has to say about Bitcoin? 117
  79. @arafkarsh arafkarsh 1. HyperLedger Architecture Volume 1 2. Creating Tokens

    in Hyperledger Fabric : https://github.com/Kunstmaan/hyperleder-fabric-kuma-token-example/ 3. Karame, Androulaki, & Capkun. (2012). Double spending fast payments in bitcoin. ACM Conference on Computer and communications security, (pp. 906-917). 4. King, N. (2012). PPCoin: Peer to peer cryptocurrency with proof of stake. 5. Kwon. (2014). Tendermint: Consensus without Mining. Cornell Edu. 6. Mazieres, D. (2015). The Stellar Consensus Protocol: Federated Model for Internet level consensus. Stellar Development Foundation. 7. Narayanan, B. F. (2016). Bitcoin and cryptocurrency technologies. Princeton: Princeton University Press. 8. O'Dwyer, & Malone. (2014). Bitcoin mining and its energy footprint. Irish Signals and Systems Conference, pp. 280-285 9. Byzantine Fault Tolerance : https://en.wikipedia.org/wiki/Byzantine_fault_tolerance 10. Building Blockchain Apps for Node.JS developers with HyperLedger Composer – Simon Stone IBM References 1. Elastic Engineering 2. Design Thinking, Lean Startup, Agile & DDD 3. Event Sourcing / CRS, Kafka 4. Apache Flink, AWS Kinesis 5. Big Data – Redis, MongoDB 6. Microservices Patterns and Monolithic Migration Patterns & Strategy 7. Microservices Testing Strategy 8. Containers (Docker), Kubernetes, Service Mesh (Istio) 9. Cloud Architecture – Hybrid, Edge, Multi Clouds 10. CI/CD – Jenkins, GitHub, Tekton 11. DevOps and SRE 12. Service Mesh Observability 13. Zero Trust & DevSecOps 118