Hands-On Blockchain for Python Developers Empowering Python developers in the world of blockchain and smart contracts (Arjuna Sky Kok) (z-library.sk, 1lib.sk, z-lib.sk)
Python
Empowering Python developers in the world of blockchain and smart contracts
6
Views
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
Hands-On Blockchain for Python Developers Copyright © 2024 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Group Product Manager: Kunal Sawant Publishing Product Manager: Akash Sharma
Page
3
Senior Editor: Esha Banerjee Technical Editor: Jubit Pincy Copy Editor: Safis Editing Project Coordinator: Manisha Singh Indexer: Manju Arasan Production Designer: Jyoti Kadam Marketing Coordinator: Sonia Chauhan First published: February 2019 Second edition: June 2024 Production reference: 1130624 Published by Packt Publishing Ltd. Grosvenor House 11 St Paul's Square Birmingham B3 1RB, UK. ISBN 978-1-80512-136-7 www.packtpub.com OceanofPDF.com
Page
4
OceanofPDF.com To the memory of my brother, Hengdra Santoso, for the unbreakable bond we shared as brothers. – Arjuna Sky Kok
Page
5
Contributors About the author Arjuna Sky Kok is a skilled software engineer with a passion for all things related to finance and technology. He lives in Jakarta, where he studied mathematics and programming at Binus University. Arjuna’s academic achievements include double degrees in Computer Science and Mathematics. Currently, he is focusing his talent in the crypto space, as he believes that DeFi and NFT will serve as the foundation for future finance. He also has a keen interest in AI, especially Generative AI. Outside of work, Arjuna enjoys watching anime, listening to J-pop songs, and playing basketball. About the reviewers Ankit Anchila is a distinguished software development professional with over a decade of industry experience. With a background in software development, Ankit brings a wealth of expertise and insights to the table. Ankit has served as a judge at numerous hackathons and has evaluated projects for prestigious awards such as the Webby, Edison, and Globee Awards. Beyond his professional achievements, Ankit is an active contributor to the software development community. He regularly shares valuable insights through articles in tech blogs, influencing and inspiring fellow developers. As a member of The International Academy of Digital
Page
6
Arts and Sciences (IADAS), Ankit continues to shape the future of digital innovation. Shivanjan Chakravorty is a distinguished Member of Technical Staff 3 at Pure Storage, where he brings a wealth of expertise to the forefront of technological innovation. Renowned for his contributions to open-source projects, especially libopenstorage, Shivanjan excels in Golang and Python. His expertise covers a wide range of technologies including Kubernetes, Machine Learning, and Generative AI. He has also worked extensively with Large Language Models (LLMs). Additionally, his scholarly work includes two published research papers in the domain of mathematical optimization. Beyond his professional pursuits, Shivanjan is an avid adventurer and a chess enthusiast, embodying a dynamic blend of intellect and passion. OceanofPDF.com
Page
7
Table of Contents Preface
Page
8
Part 1: Blockchain and Smart Contract 1 Introduction to Blockchain Programming Technical requirements The rise of cryptocurrency and blockchain Blockchain technology Signing data in blockchain From linked list to blockchain Cryptography Symmetric and asymmetric cryptography The hashing function Proof of work Consensus
Page
9
Blockchain as a technology that prevents cheating Proof of stake Coding on the blockchain Other types of blockchain programmers What does it mean to be a blockchain programmer? The scope of this book Summary References 2 Smart Contract Fundamentals Technical requirements Smart contract Secure from cheating
Page
10
Censorship resistance Practical applications Summary 3 Using Vyper to Implement a Smart Contract Technical requirements Setting up Vyper Data types Boolean Signed integer Unsigned integer Decimal Address Fixed-size byte array
Page
11
Byte array String Enum List Dynamic arrays Struct Mapping Functions Mutability Control structures Environment variables Event logging Interface Summary
Page
12
Part 2: Web3 and Ape Framework 4 Using Web3.py to Interact with Smart Contracts Technical requirements Installing web3.py Ganache Geth Deploying a smart contract Interacting with smart contracts Summary 5 Ape Framework
Page
13
Technical requirements Installing Ape Framework Developing smart contracts Compiling a smart contract Deploying the smart contract Testing smart contracts Networks in blockchain Summary 6 Building a Practical Decentralized Application Technical requirements Writing the voting smart contract Writing the unit test of the voting smart contract
Page
14
Adding delegation to the voting smart contract The benefits of the decentralized nature of a voting smart contract Ideas for improvements Summary
Page
15
Part 3: Graphical User Interface Applications 7 Front-End Decentralized Application Technical requirements Using the voting smart contract with scripts Compiling the smart contract Creating accounts Setting up the Geth development blockchain Deploying the smart contract onto blockchain Creating and running the scripts Installing the PySide library Creating the voting GUI application
Page
16
Connecting the GUI application with the smart contract Summary 8 Cryptocurrency Wallet Technical requirements What is a wallet? Mnemonic keys Developing a cryptocurrency wallet Wallet UX Summary
Page
17
Part 4: Related Technologies 9 InterPlanetary: A Brave New File System Technical requirements The motivation behind IPFS Merkle DAG Merkle tree Directed Acrylic Graph Content addressing The Merkle DAG data structure Peer-to-peer networking The notion of proximity of data and nodes XOR distance
Page
18
Buckets Summary 10 Implementing a Decentralized Application Using IPFS Technical requirements Installing the IPFS software and its library Exploring the IPFS Python library The architecture of the decentralized video- sharing application The architecture of the video-sharing smart contract The architecture of the video-sharing web application Writing the video-sharing smart contract Creating a Bootstrap script
Page
19
Building the video-sharing web application Views Models Templates URLs Demo Summary 11 Exploring Layer 2 Technical requirements Understanding L2 How L2 works Optimistic rollups Zk rollups
Page
20
Looking at examples of L2 Polygon Arbitrum Optimism Base Starknet zkSync Deploying smart contracts to L2 Introducing the bridge technology Bridging ETH Bridging ERC-20 tokens Native ERC-20 tokens Messages Sending messages from L1 to L2 Sending messages from L2 to L1
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
【One-Line Pitch】
A practical bridge from Python fundamentals to working decentralized applications: you build blockchains, smart contracts, wallets, and NFT tools with Python rather than reading about them abstractly. Best for Python developers who want hands-on blockchain skills without abandoning the language they already know.
【Book Arc】
- **Opening (~0%–10%)**: Establishes why tamper-evident, append-only records matter, then builds a minimal blockchain in Python — blocks, parent hashes, and the integrity problem that distributed consensus solves.
- **Early (~10%–32%)**: Moves from raw blockchain concepts into smart contract development — Vyper syntax, state variables, events, and the tooling (Ganache, Geth, Web3.py, Ape Framework) needed to compile, deploy, and test contracts.
- **Middle (~32%–50%)**: Shifts to application building: a PySide GUI voting app, a cryptocurrency wallet that holds and transfers ETH, and the IPFS/Merkle DAG foundations for decentralized file storage.
- **Late (~50%–75%)**: Extends into decentralized video sharing over IPFS, Layer 2 scaling solutions, and deploying contracts to L2 platforms for cheaper, faster transactions.
- **Ending (~75%–100%)**: Token and NFT territory — ERC-20 tokens, ERC-721 NFTs, and NFT marketplace smart contracts for buying, selling, and trading digital assets.
【Key Takeaways】
- **Blockchain integrity comes from distribution, not secrecy** (Opening): A single copy can be edited; many copies make tampering detectable. This is the conceptual spine the whole book hangs on.
- **Python is a first-class blockchain development language** (Early): Web3.py, Ape Framework, and Vyper let you stay in Python for deployment, testing, and interaction instead of switching to JavaScript tooling.
- **Smart contracts are programs with real financial consequences** (Early): State variables, events, and access control (internal vs. external functions) are not academic — mistakes move real value.
- **Local development chains are essential for iteration** (Early): Ganache and Geth in dev mode give you funded accounts and disposable state, so you can test transfers and deployments without risking mainnet funds.
- **Wallets are deceptively simple but error-prone** (Middle): Holding and sending crypto is straightforward; address validation and safe input handling are where users lose money.
- **IPFS stores content by hash, not location** (Middle): Merkle DAGs and versioning via linked lists explain why decentralized storage behaves differently from a normal filesystem.
- **Layer 2 is the practical answer to Ethereum's throughput limits** (Late): Deploying to L2 platforms is framed as the way to build cost-effective dApps rather than fighting mainnet congestion.
- **Tokens and NFTs are standards-driven** (Ending): ERC-20 and ERC-721 give you interoperable building blocks; marketplaces are the application layer on top of those standards.
【Reading Tips】
- **Deep-read the opening blockchain implementation** — it is the mental model everything else depends on; skimming it makes later contract chapters feel like magic.
- **Skim the tooling installation sections** (Ganache, Geth, Ape setup) on first pass; return to them as reference when you actually deploy.
- **Treat the project chapters (wallet, voting app, video sharing) as build-along exercises** — the value is in running the code, not reading it.
- **Watch the Vyper-specific constraints** (fixed-size arrays, MAX_NUM_PROPOSALS, internal vs. external functions); these are common sources of confusion for developers coming from Python.
- **Take away the deployment pipeline**: compile → test locally → deploy to testnet/L2 → interact via Web3.py. That workflow transfers to any blockchain project.
【Coverage Limits】
The excerpts cover the book's structure and major themes but do not include full code listings or detailed chapter content for every topic; some sections (particularly later NFT marketplace and L2 chapters) are represented only by chapter summaries rather than substantive excerpts.
Passage locations
Excerpt 1
smart contract that mints and transfers ownership of these unique digital assets. Chapter 14, Writing NFT Marketplace Smart Contracts, dives deep into the wo...
View in text
Excerpt 2
ng the transferring token method. This, I believe, is fair. A smart contract is a truly “open source” program! Censorship resistance Another property of smar...
View in text
Excerpt 3
cted to the Sepolia network. Now, head back to your project. But before you are able to deploy the smart contract to the Sepolia network, you need to fill yo...
View in text
Excerpt 4
side the thread class with the connect method to a function named update_balance of this widget class that you’ll define later. Then let’s define the update_...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay