Python Blockchain - Client Class


The Client class generates the private and public keys by using the built-in Python RSA algorithm. The interested reader may refer to this tutorial for the implementation of RSA. During the object initialization, we create private and public keys and store their values in the instance variable.

self._private_key = RSA.generate(1024, random)
self._public_key = self._private_key.publickey()

Note that you should never lose your private key. For record keeping, the generated private key may be copied on a secured external storage or you may simply write down the ASCII representation of it on a piece of paper.

The generated public key will be used as the client’s identity. For this, we define a property called identity that returns the HEX representation of the public key.

   def identity(self):

The identity is unique to each client and can be made publicly available. Anybody would be able to send virtual currency to you using this identity and it will get added to your wallet.

The full code for the Client class is shown here −

class Client:
   def __init__(self):
      random =
      self._private_key = RSA.generate(1024, random)
      self._public_key = self._private_key.publickey()
      self._signer =

   def identity(self):

Testing Client

Now, we will write code that will illustrate how to use the Client class −

Dinesh = Client()
print (Dinesh.identity)

The above code creates an instance of Client and assigns it to the variable Dinesh. We print the public key of Dinesh by calling its identity method. The output is shown here −


Now, we let us move on to create a transaction in the next chapter.

Useful Video Courses


Python Online Training

Most Popular

187 Lectures 17.5 hours

Malhar Lathkar


Python Essentials Online Training

55 Lectures 8 hours

Arnab Chakraborty


Learn Python Programming in 100 Easy Steps

136 Lectures 11 hours

In28Minutes Official


Python with Data Science

75 Lectures 13 hours

Eduonix Learning Solutions


Python 3 from scratch to become a developer in demand

70 Lectures 8.5 hours

Lets Kode It


Python Data Science basics with Numpy, Pandas and Matplotlib

63 Lectures 6 hours

Abhilash Nelson