Book Image

Hands-On Blockchain for Python Developers

By : Arjuna Sky Kok
Book Image

Hands-On Blockchain for Python Developers

By: Arjuna Sky Kok

Overview of this book

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.
Table of Contents (19 chapters)
Free Chapter
1
Section 1: Blockchain and Smart Contracts
5
Section 2: Web3 and Populus
9
Section 3: Frontend Decentralized Applications
11
Section 4: Cryptocurrency and Wallets
14
Section 5: Decentralized Filesystem

Content hashing

In the IPFS quick start documentation (https://docs.ipfs.io/introduction/usage), the first thing that they teach you is to download the cute cat picture. Use the following code to do this:

$ ipfs cat /ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg >cat.jpg
$ eog cat.jpg

When you run the preceding code, the cat picture will be downloaded and you will get the following as output:

eog is an image viewer in Ubuntu.

To respect the tradition, let's create a Python script to download the preceding image programmatically with Python and name the script download_cute_cat_picture.py:

import ipfsapi


c = ipfsapi.connect()
cute_cat_picture = 'QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg'
c.get(cute_cat_picture)

After executing this script, the image will be named cat.jpg in your directory.

As you may have noticed, there is a cat.jpg filename...