--- tags: tezos title: Notes for our standard tech presentation --- # Arthur talk notes ###### tags: `tezos` ## Tezos introduction - Security First - Functional Programming mindset - Better allows for formal verification - Immutability and pure functions help avoid bugs - Proof of Stake - CO2 efficiency - Proof of Work is a "race to the bottom" - Token ownership disincentivizes malicious baking - On-chain governance - Fast rollout of protocol features - Reduces risks of contentious forks ## Structure of a Dapp - "**D**ecentralized **App**" - Fuzzy definition - App based on a public blockchain - User sovereignty - Limited or no "admin" write access to important state - Architecture outline - UI: usually runs in browser - Middleware (optional) - Blockchain as Single Source of Truth - On-chain smart contract(s) ### Smart Contracts - What is a smart contract - Technological enforcement of business rules - Vending machine analogy - Can remove soda, but only as much as you paid for - Can remove coins, but only as much as you got in change - On a public blockchain: - Decentralized - Autonomous - Complexity restrictions - Due to distributed consensus - Similar power to a '70s microcomputer - O(1) to low O(log(n)) complexity requirement with regards to state vector size ### Smart Contracts on Tezos - Michelson language - Native language of Tezos' smart contract VM - Human readable, assembler-like syntax - Stack based - Strongly typed, with ML-inspired type system - Functional Programming features (lambdas, currying) - High level languages - Several smart contract languages are being developed, the best will be adopted and will survive - SmartPy - Python library with optional lexer for syntactic sugar - Metaprogramming: Python code generates Michelson code - Python is familiar to many programmers - Several convenience features - Unit testing framework built in - Lazily loaded code and other built-in optimizations - Criticism: Python is a suboptimal fit for Tezos - Procedural vs. functional mindset - Weak typing vs. strong typing mindset - Ligo - Strongly typed functional language, based on ML - Compiled - Multiple syntaxes for familiarity, above the same language backend - CameLigo based on OCaml - JsLigo based on Javascript - PascaLigo, ReasonLigo - Culturally a good fit for Tezos, rooted in OCaml culture (especially CameLigo) - Clear mapping between high level code and compiler output - Criticism: Fewer convenience features than SmartPy - Unit testing needs to be done by hand / scripted - The Ligo compiler provides a `run-fuction` primitive - Unfriendly compiler error messages ### Middleware / Indexer - Provides speed and convenience for the UI - Blockchain is the Single Source of Truth - Blockchain queries are slow - Blockchain queries are inconvenient and restricted - Big, generalist, public indexers - They keep track of the entire chain state - They have knowledge of the common token types and can display much information about them - Main examples - Better Call Dev - TzKT - DipDup is a layer on top of TzKT which provides value-added services - Centrally run instances - https://better-call.dev/ and https://tzkt.io/ - Limited resources and high user demand - Historical reliability issues under load - Docker images are available to run in-house - Indexing the whole chain is resource intensive - Application-specific middleware - DApps may have their own custom middleware - Developed as a traditional serverside backend - Usually contains domain-specific logic - Uses the blockchain as a data access layer - Focused on the DApp's own smart contract(s) ### Front-end - Taquito - Javascript library for interacting with Tezos node - Provides smart contract abstraction - Written in typescript and major release version same as tezos node - Wallets/Beacon - Connect to Tezos nodes - Key management - Locally stored keypairs or HD wallet - Hardware wallet integration (recommended) - OAuth-derived private keys (easy onboarding) ### PyTezos - Python library for interacting with Tezos nodes - Makes contract interaction easy - One can mint an NFT in 5 lines of code (example to come) - Potential uses - Power user interface through Python REPL - Accessing on-chain contract state - Generating, signing and submitting chain operations - Automated integration testing of smart contracts - Blockchain connectivity for DApp-specific custom middleware ### Flextesa - Locally run blockchain for developer testing - Docker images are available for quick deployment