Python blockchain client development
Python Blockchain Client Development
A client is someone who holds TPCoins and trades these for goods/services from other vendors on the network (including their own). We’ll define a Client class for this purpose. To create a globally unique identity for the client, we use PKI (Public Key Infrastructure). Let’s explore this in detail in this chapter.
A client should be able to send money from their wallet to another known person. Similarly, the client should be able to receive money from a third party. To spend money, the client will create a transaction specifying the sender’s name and the amount to be paid. To receive money, the client will provide their identity to the third party—essentially, the sender of the money. We will not store the balance of funds held by the client in their wallet. During the transaction process, we will calculate the actual balance to ensure that the client has enough to make the payment.
To develop the Client class and the rest of the code in the project, we will need to import a number of Python libraries. These libraries are listed below –
# import libraries
import hashlib
import random
import string
import json
import binascii
import numpy as np
import pandas as pd
import pylab as pl
import logging
import datetime
import collections
In addition to the standard libraries mentioned above, we will also need to sign our transactions, create hashes of objects, and so on. For this, you will need to import the following libraries −
# The following imports are required by PKI
import Crypto
import Crypto.Random
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
In the next chapter, let’s talk about client classes.