Hands-On Blockchain for Python Developers

Book Description

Implement real-world decentralized applications using Python, Vyper, Populus, and Ethereum

Key Features

  • Stay up-to-date with everything you need to know about the blockchain ecosystem
  • Implement smart contracts, wallets, and decentralized applications(DApps) using Python libraries
  • Get deeper insights into storing content in a distributed storage platform

Book Description

Blockchain is seen as the main technological solution that works as a public ledger for all cryptocurrency transactions. This book serves as a practical guide to developing a full-fledged decentralized application with Python to interact with the various building blocks of blockchain applications.

Hands-On Blockchain for Python Developers starts by demonstrating how blockchain technology and cryptocurrency hashing works. You will understand the fundamentals and benefits of smart contracts such as censorship resistance and transaction accuracy. As you steadily progress, you'll go on to build smart contracts using Vyper, which has a similar syntax to Python. This experience will further help you unravel the other benefits of smart contracts, including reliable storage and backup, and efficiency. You'll also use web3.py to interact with smart contracts and leverage the power of both the web3.py and Populus framework to build decentralized applications that offer security and seamless integration with cryptocurrencies. As you explore later chapters, you'll learn how to create your own token on top of Ethereum and build a cryptocurrency wallet graphical user interface (GUI) that can handle Ethereum and Ethereum Request for Comments (ERC-20) tokens using the PySide2 library. This will enable users to seamlessly store, send, and receive digital money. Toward the end, you'll implement InterPlanetary File System (IPFS) technology in your decentralized application to provide a peer-to-peer filesystem that can store and expose media.

By the end of this book, you'll be well-versed in blockchain programming and be able to build end-to-end decentralized applications on a range of domains using Python.

What you will learn

  • Understand blockchain technology and what makes it an immutable database
  • Use the features of web3.py API to interact with the smart contract
  • Create your own cryptocurrency and token in Ethereum using Vyper
  • Use IPFS features to store content on the decentralized storage platform
  • Implement a Twitter-like decentralized application with a desktop frontend
  • Build decentralized applications in the shape of console, web, and desktop applications

Who this book is for

If you are a Python developer who wants to enter the world of blockchain, Hands-On Blockchain for Python Developers is for you. The book will be your go-to guide to becoming well-versed with the blockchain ecosystem and building your own decentralized applications using Python and library support.

Publisher Resources

View/Submit Errata

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Blockchain for Python Developers
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Foreword
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Section 1: Blockchain and Smart Contracts
  8. Introduction to Blockchain Programming
    1. The rise of cryptocurrency and blockchain
    2. Blockchain technology
      1. Signing data in blockchain
      2. From linked list to blockchain
    3. Cryptography
      1. Symmetric and asymmetric cryptography
    4. The hashing function
      1. Proof of work
    5. Consensus
    6. Coding on the blockchain
      1. Other types of blockchain programmers
    7. Summary
    8. References
  9. Smart Contract Fundamentals
    1. Installing an Ethereum development environment
      1. Installing Node.js
      2. Installing Truffle and Solidity
      3. Installing Ganache
    2. Writing a smart contract
    3. Deploying a smart contract to Ethereum blockchain
    4. Interacting with smart contracts
      1. Sending ether to smart contracts
    5. Why smart contracts?
    6. Summary
    7. Further reading
  10. Implementing Smart Contracts Using Vyper
    1. Motivations behind Vyper
    2. Installing Vyper
    3. Creating a smart contract with Vyper
    4. Deploying a smart contract to Ganache
      1. Interacting with smart contracts
    5. Going deeper into Vyper
      1. Data types
      2. Withdrawing ethers
      3. Other data types
      4. Useful built-in functions
      5. Events
    6. Interacting with other smart contracts
    7. Compiling code programmatically
    8. Other tricks
    9. Summary
  11. Section 2: Web3 and Populus
  12. Interacting with Smart Contracts Using Web3
    1. Introduction to decentralized applications
      1. Installing web3
    2. Geth
      1. Geth console
    3. Understanding the web3.py library
      1. Gas and gas price
      2. Nonce
      3. Creating a transaction on Rinkeby
    4. Interacting with smart contracts using web3.py
      1. Launching a smart contract with Geth
      2. Launching a smart contract with web3
      3. Playing with a smart contract
    5. Summary
  13. Populus Development Framework
    1. Setting up Populus
      1. Adding support for Vyper
    2. Smart contract unit test
      1. Using arguments in the constructor
    3. Deploying a smart contract with Populus
    4. Summary
  14. Building a Practical Decentralized Application
    1. Developing a simple voting application
      1. Deploying a smart contract that has arguments in its constructor
    2. Developing a commercial voting application
    3. Developing a token-based voting application
    4. Summary
    5. Further reading
  15. Section 3: Frontend Decentralized Applications
  16. Frontend Decentralized Application
    1. Setting up the Qt GUI library
      1. Choosing a GUI library
      2. Installing Qt for Python
    2. Crash course on Qt for Python
      1. Layout
      2. Other widgets
      3. Callback
      4. Threading
    3. Writing the smart contract for the Twitter–like application
      1. Test
      2. Fixtures
    4. Building the GUI frontend for the Twitter–like application
    5. Summary
  17. Section 4: Cryptocurrency and Wallets
  18. Creating Token in Ethereum
    1. Token smart contract
      1. Mist
    2. ERC20
    3. Selling a token
    4. Stable coin
    5. Summary
    6. Further reading
  19. Cryptocurrency Wallet
    1. Advanced features of the PySide2 library
      1. Testing application
      2. Advanced features of Qt for Python or PySide2
    2. Building a cryptocurrency wallet
      1. Blockchain class
      2. Thread classes
      3. Identicon and Icons
      4. Building widgets
        1. Account widget
        2. Sending a transaction widget
        3. Token widget
        4. Test
    3. Considerations when building a cryptocurrency wallet
      1. Security
      2. User experience
    4. Summary
  20. Section 5: Decentralized Filesystem
  21. InterPlanetary - A Brave New File System
    1. The motivation behind IPFS
    2. Merkle DAG
      1. Merkle tree
      2. Directive Acrylic Graphs (DAGs)
      3. Content addressing
      4. The Merkle DAG data structure
    3. Peer-to-peer networking
      1. The notion of closeness of data and nodes
      2. XOR distance
      3. Buckets
    4. Summary
  22. Using ipfsapi to Interact with IPFS
    1. Installing the IPFS software and its library
    2. Content hashing
      1. Protobuf
      2. Multihash
      3. Base58
      4. Combining protobuf, multihash, and base58
    3. The ipfsapi API
      1. IPNS
      2. Pinning
      3. Pubsub
      4. Mutable File System
      5. Other APIs
    4. Summary
    5. Further reading
  23. Implementing a Decentralized Application Using IPFS
    1. Architecture of the decentralized video-sharing application
      1. Architecture of a video-sharing smart contract
      2. Architecture of a video-sharing web application
    2. Writing the video-sharing smart contract
      1. Launching a private Ethereum blockchain
      2. Creating a bootstrap script
    3. Building the video-sharing web application
      1. Views
      2. Models
      3. Templates
      4. Urls
      5. Demo
    4. Note
    5. Summary
    6. Further reading
  24. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Hands-On Blockchain for Python Developers
  • Author(s): Arjuna Sky Kok
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781788627856