Become an NFT Developer with Best Practice Way Part 2: Implement How Blockchain works using Python

Feri Lukmansyah
Remote Worker Indonesia
2 min readNov 10, 2021
image from Unsplash

in the previous chapter, we discuss the fundamental of blockchain, so in this chapter, we will discuss how to implement Blockchain Works using Python, so let’s see the table of content

  • Creating Blockchain Class and Constructor
  • Creating Method to get Transaction
  • Creating Sample Transaction

Creating Blockchain Class and Constructor

in first step creating blockchain class and the constructor

in this constructor, we have a previous hash property and transaction list parameter, and we join all the transaction list with the previous hash and separate them with -

after separating the string we created a hash with the sha256 method from the hashlib module on python.

Creating a method to get Transaction

after creating the constructor, we need to get transaction result so creating a method for it

in this method, we print the result of the transaction

Creating Sample Transaction

now creating simple transactions to see how blockchain works

and we see if we changed data the hash is changed differently

if data changed the token is changed frequently

Conclusion

In this simple program, we explain how blockchains work and create the unique token using hash, so we can easily understand it, thanks for reading, source code available on Github, see you in the next chapter

--

--