Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Hands-On Blockchain for Python Developers
Hands-On Blockchain for Python Developers

Hands-On Blockchain for Python Developers

Gain blockchain programming skills to build decentralized applications using Python

€36.99
By Arjuna Sky Kok
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7 (3 Ratings)
Pages 450
Published in Feb 2019
Product Type Paperback
Edition 1st Edition
Hands-On Blockchain for Python Developers

Packt Subscriptions

See our plans and pricing
Modal Close icon
€11.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€119.99 billed annually
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€169.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 6,500+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Blockchain for Python Developers

Smart Contract Fundamentals

In this chapter, we will explore the basics of smart contracts. While in Bitcoin we store value, in Ethereum we store code. The code that we store in Ethereum is called a smart contract. A smart contract is a trustless code, meaning the integrity of the code is guarded by algorithms and cryptography. We can store, the code which is censorship-resistant and is able to avoid third-party interference even from the developer of the smart contract. This opens possibilities of creating many types of application, such as transparent digital tokens, trustless crowdsale, secure voting systems, and autonomous organization.

The following topics will be covered in this chapter:

  • Installing an Ethereum development environment
  • Writing a smart contract
  • Deploying a smart contract to Ethereum blockchain
  • Interacting with smart contracts
  • Why smart contracts?
  • ...

Installing an Ethereum development environment

It's time to create a smart contract. If you are familiar with Solidity, Truffle, Ganache, and the smart contract fundamentals, you can skip ahead to Chapter 3, Implementing Smart Contracts Using Vyper. Here, we will focus on the content of a smart contract created with Solidity. Throughout the remainder of the book, we will use the Vyper programming language to develop a smart contract. However, we will still use the same development environment (such as Ganache) in the rest of the book.

Installing Node.js

Node.js is a popular framework for developing web applications, mobile applications, and decentralized applications. Head to https://nodejs.org and download the latest...

Writing a smart contract

Once all the requisite software is installed, we can start writing a smart contract. First, we will create a new directory, and then initialize it with the Truffle development tool:

$ mkdir my_first_smart_contract
$ cd my_first_smart_contract
$ truffle init

The output of the truffle init command is as follows:

This will command Truffle to initialize your directory to be a smart contract development project. A couple of directories are  available to you when developing a smart contract in this project directory:

$ ls
contracts migrations test truffle-config.js

You usually incorporate a smart contract's source code in the contracts folder. The migrations folder holds the files that are used in the deployment of smart contracts, and the test folder holds the test files. You can configure the smart contract deployment settings in the truffle-config...

Deploying a smart contract to Ethereum blockchain

These are the steps for deploying a smart contract to Ethereum blockchain with Truffle:

  1. Write a migration script: To deploy your smart contract, you need to write a migration file. Create a new file named migrations/2_deploy_donation.js. Then, we fill this file with the following script:
var Donation = artifacts.require("./Donation.sol");

module.exports = function(deployer) {
deployer.deploy(Donation);
};

As for the migrations/1_initial_migration.js and contracts/Migrations.sol files, we leave these as they are for now. Truffle needs these files in order to deploy a smart contract.

  1. Launch Ganache (the blockchain for Ethereum development): Now you need to launch Ganache. Assuming you have been given proper permission, run the following command line to execute the file:
./ganache-1.2.3-x86_64...

Interacting with smart contracts

To interact with your smart contract that resides in Ethereum blockchain, execute this command inside your Truffle project directory:

$ truffle console

Then, in the truffle console prompt, execute the following command:

truffle(development)> Donation.deployed().then(function(instance) { return instance.useless_variable.call(); });
'Donation string'

If you are confused about then, the Truffle console uses the concept of callback, on which accessing the smart contract object is executed asynchronously. This statement in the Truffle console returns immediately before the callback is being executed. In the callback function, you will accept the smart contract instance as an instance parameter. Then, we can access our useless_variable variable from this instance parameter. Then, to retrieve the value, we have to execute the call...

Why smart contracts?

You have now seen a smart contract in action. So what is all the fuss about? What can smart contracts do that traditional programs (normal web applications) can't? When it comes to changing the value of a variable in a program that lives on the network, we can use remote procedure call. More commonly, we can store a variable in a database and people can change the value in the database from a web application. When sending money, we can integrate our web application with Stripe or PayPal, giving us the means to send money. Alternatively, you could create a table in a database for storing digital money. Ether in Ethereum is basically digital money. In fact, a normal web application can do everything a smart contract can do, but faster and cheaper. The key difference is that blockchain solutions can be trustless. This means that you can put trust in...

Summary

In this chapter, we explored how to install Solidity development tools: Node.js, Truffle, or Ganache. We then learned how to write a smart contract and compile it. After that, we looked at the concept of deploying a smart contract to Ethereum blockchain, followed by interacting with a smart contract being deployed with the Truffle console tool. We gained an understanding of the concept of sending ether to a smart contract and gas usage when executing a function in a smart contract. In the last step, we familiarized ourselves with why the smart concept works so well, with the potential to create a program that is censorship-resistant and transparent, and that cannot be circumvented.

In the next chapter, we will learn how to implement smart contracts using Vyper.

Left arrow icon Right arrow icon
Download code icon Download Code

Key Benefits

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

What You Will Learn

Who Is This Book 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.

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.
Category:
Languages:
Concepts:
Tools:

Frequently bought together


Stars icon
Total 134.97
Hands-On Blockchain for Python Developers
€36.99
Mastering Blockchain
€67.99
Mastering Ethereum
€29.99
Total 134.97 Stars icon

Table of Contents

(12 Chapters)
Introduction to Blockchain Programming Chevron down icon Chevron up icon
Smart Contract Fundamentals Chevron down icon Chevron up icon
Implementing Smart Contracts Using Vyper Chevron down icon Chevron up icon
Interacting with Smart Contracts Using Web3 Chevron down icon Chevron up icon
Populus Development Framework Chevron down icon Chevron up icon
Building a Practical Decentralized Application Chevron down icon Chevron up icon
Frontend Decentralized Application Chevron down icon Chevron up icon
Creating Token in Ethereum Chevron down icon Chevron up icon
Cryptocurrency Wallet Chevron down icon Chevron up icon
InterPlanetary - A Brave New File System Chevron down icon Chevron up icon
Using ipfsapi to Interact with IPFS Chevron down icon Chevron up icon
Implementing a Decentralized Application Using IPFS Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(3 Ratings)
5 star 33.3%
4 star 0%
3 star 66.7%
2 star 0%
1 star 0%
Amazon Customer Aug 17, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is well written. Straight to point, without unnecessary detail. One thing I found fascinating is the hands-on approach. i give it to Arjuna. More power to you. I highly recommend. I am now at the 5th Chapter, and everything work as breeze.
Amazon Verified review Amazon
Marcos B. Sep 18, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book should be updated, I had to literally read it alongside with the Brownie and Vyper documentation because Populous is no longer maintained, and Vyper itself has changed a lot as well.Overall, it is a nice book. However, bear in mind that you are gonna be reading a lot of documentation.I would had loved to see a chapter about contract's Inheritance capability instead of IPFS.
Amazon Verified review Amazon
MR M KORSIKOV May 17, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Author did a great job describing step by step contract creation however a lot of app versions and libraries are no longer supported. After chapter 3 you won't be able to see in practice what is described in the book.I would recommend being anything not older than 1 (one) year to benefit from practical application of knowledge.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon