What's the Deal with Blockchain?

What's the Deal with Blockchain?

If you spend more than a few minutes on tech Twitter these days, you are going to run into the wave of Web 3 enthusiasm sweeping through the community. My first instinct was to ignore the whole topic as a shiny object aiming to distract me from my Python related learning. This was pretty easy to do when I thought Web 3 was all about cryptocurrency. Then I kept reading about the blockchain that is really what this Web 3 thing is about. The more you learn about blockchain and how it works, the harder it is to keep your mind from racing with ideas around how it could be leveraged to solve current problems. Need to authenticate votes for an election? Blockchain. Need a payment processor that doesn't lean on centralized banking and can legally process transactions for your cannabis dispensary? Blockchain. Need to sell your digital art online while protecting your intellectual property? You guessed it! Blockchain.

That last example is the one that finally got me down the rabbit hole. My wife is a graphic designer and we were curious what it would take to create and sell NFT's she could design. I was puzzled as to what was to stop anyone from copying the image and just stealing it and decided I needed to understand the process better. At the same time, I discovered Learn the Basics of Blockchain with Python on Codecademy Pro. The link to Python let me justify this learning detour and I added the course to my learning list.

Parts of a Block, Blocks on the Chain

You have probably seen the blockchain explained as blocks of data chained together to form a decentralized network but, what does that actually mean? What is in a block? What benefit is there to chaining them together? How can something so decentralized be secured? How does all of this apply to NFT's?

Disclaimer: I am no where near being an expert on anything to do with blockchain. This info is meant for others who are just learning some of this same information in the hope that it can add another point of view and, possibly, greater understanding.

Blocks are made of four parts: a timestamp, the data to be stored, a hash, and a reference to the hash of the immediately prior block in the chain. The first two items are fairly straight-forward to explain. The timestamp is the date and time the transaction took place. The data is what is being stored on the blockchain. This could be anything from a financial transaction to a database, or even a novel or list of passwords. What about hashing? What does that mean and how does it work?

Hashing is a deep and complex topic. This is the ELI5 version. When creating a hash, data is input and a string of characters is output. The hash will be the same number of characters regardless of the length/size of the data input (most common length is 256 characters). An important property of the hash is being deterministic which means the same input will always produce the same output but the reverse is not true. The process of creating a hash from data input is one way only which prevents attempts at reverse engineering the hash to decipher the data input.

There is a bunch of big math function magic that goes into creating and solving hashes. If this sounds like something you want to learn more deeply, there are plenty of online resources where you can take a deep dive. For our purposes, just know each block gets its own hash as well as a reference to the hash of the previous block in the chain. If data in an individual block is altered in any way, a new hash is generated for that block. This means the block's hash will no longer match the previous hash reference in the next block and prevents manipulation of data once it is posted to the blockchain. This makes the data blocks immutable in nature.

Blockchain transactions are verified by consensus. In very simple terms, a block is presented to a network of participating miners who go to work doing Big Fancy Math things to determine if the information attached to the block is valid. This process takes a lot of computing power and is often energy intensive. This is where "gas fees" come in. Users of the blockchain pay a fee to have their transaction data posted which helps to reward miners for their work and encourage them to continue to participate in block validation. Once 51% of those working to validate a block agree the information is correct and authentic, the block is considered verified. A concept called Proof-of-Work adds cryptography to the mix to add an additional layer of security, though I must admit to not understanding well how that piece works.

NFT? WTF?

How does this apply to NFT's? Why would anyone buy one when you can just save the image off the web? The key here is to realize you are not paying for the image, you are paying for the block where the transaction data related to your purchase is stored. Think of this as a certificate of authenticity which allows you to verify your ownership of the genuine article. You now have the capability to generate digital items, allow them to assume a market value, and securely process the purchase in a transaction that protects the interest of both the buyer and seller. Personally, I am most excited about the implications of NFT and blockchain for gaming. I have invested more hours than I'd like to admit in various mobile app games which reply upon amassing economic resources to advance within the gaming universe. I ended up rather deep in a rabbit hole on one game that shall remain nameless but, I remember some sketchy PayPal transactions and trading log-in credentials in trying to acquire resources from other players, purchase their advanced player accounts, etc. Gamers have made secondary markets for these type of transactions for a long time without the protection of NFT/blockchain proof of ownership. Up until now, it's been a go for it and hope you don't get ripped off in the process type of endeavor. I would love to see a secure secondary market that brings gaming economies into the real world with less risk of fraud and loss to participants.

What About Python?

What, indeed? I am still working my way through the lesson but I am learning about using Python classes to construct and assemble the elements required for a block. I was super excited to learn I could import a sha256 algorithm from hashlib and use it to generate my own hashes. I had no idea my Python had a library related to hashing built in and I am eager to see what other capabilities are included. Next steps will include building the blockchain class and hardcoding the Genesis block to start the chain. This step of tying Python back to building blockchain components brings the whole thing full circle for me and leaves my brain humming with potential and ideas. How about you?