Hey, Mom! Talking to My Mother #1018 - Learn Blockchains by Building One
Hi Mom,
I am anti-hype. I have always been anti-hype.
I am not sold on Blockchain.
But then, I am just reacting to hype. I have not really explored it.
A friend posted this link to Facebook, and I liked it.
Blockchain is not only crappy technology but a bad vision for the future
I have never been a band wagon guy.
But I have a prejudice against hype. I am most likely to go against something just because of the hype than to be for it.
Also, I save things and hug them close that I feel deserve the hype, like the Harry Potter books.
So when this article came through MEDIUM, I decided to give it a look.
What? I can use my Python skills to make a blockchain?
Hmmm that may be worth some time. It's a quick and relatively easy project.
Also, I have been meaning to download Pycharm, and so this may give me an excuse to do so.
Here's how.
FROM -
https://hackernoon.com/learn-blockchains-by-building-one-117428612f46
Learn Blockchains by Building One
The fastest way to learn how Blockchains work is to build one
You’re here because, like me, you’re psyched about the rise of Cryptocurrencies. And you want to know how Blockchains work—the fundamental technology behind them.
But understanding Blockchains isn’t easy—or at least wasn’t for me. I trudged through dense videos, followed porous tutorials, and dealt with the amplified frustration of too few examples.
I like learning by doing. It forces me to deal with the subject matter at a code level, which gets it sticking. If you do the same, at the end of this guide you’ll have a functioning Blockchain with a solid grasp of how they work.
Before you get started…
Remember that a blockchain is an immutable, sequential chain of records called Blocks. They can contain transactions, files or any data you like, really. But the important thing is that they’re chained together using hashes.
If you aren’t sure what a hash is, here’s an explanation.
Who is this guide aimed at? You should be comfy reading and writing some basic Python, as well as have some understanding of how HTTP requests work, since we’ll be talking to our Blockchain over HTTP.
What do I need? Make sure that Python 3.6+ (along with
pip
) is installed. You’ll also need to install Flask and the wonderful Requests library: pip install Flask==0.12.2 requests==2.18.4
Oh, you’ll also need an HTTP Client, like Postman or cURL. But anything will do.
Where’s the final code? The source code is available here.
Step 1: Building a Blockchain
Open up your favourite text editor or IDE, personally I ❤️ PyCharm. Create a new file, called
blockchain.py
. We’ll only use a single file, but if you get lost, you can always refer to the source code.Representing a Blockchain
We’ll create a
Blockchain
class whose constructor creates an initial empty list (to store our blockchain), and another to store transactions. Here’s the blueprint for our class:
Our
Blockchain
class is responsible for managing the chain. It will store transactions and have some helper methods for adding new blocks to the chain. Let’s start fleshing out some methods.What does a Block look like?
Each Block has an index, a timestamp (in Unix time), a list of transactions, a proof (more on that later), and the hash of the previous Block.
Here’s an example of what a single Block looks like:
At this point, the idea of a chain should be apparent—each new block contains within itself, the hash of the previous Block. This is crucial because it’s what gives blockchains immutability: If an attacker corrupted an earlier Block in the chain then all subsequent blocks will contain incorrect hashes.
Does this make sense? If it doesn’t, take some time to let it sink in—it’s the core idea behind blockchains.
Adding Transactions to a Block
We’ll need a way of adding transactions to a Block. Our
new_transaction()
method is responsible for this, and it’s pretty straight-forward:
After
new_transaction()
adds a transaction to the list, it returns the index of the block which the transaction will be added to—the next one to be mined.This will be useful later on, to the user submitting the transaction.Creating new Blocks
When our
Blockchain
is instantiated we’ll need to seed it with a genesis block—a block with no predecessors. We’ll also need to add a “proof” to our genesis block which is the result of mining (or proof of work). We’ll talk more about mining later.
In addition to creating the genesis block in our constructor, we’ll also flesh out the methods for
new_block()
, new_transaction()
and hash()
:and continue reading....
https://hackernoon.com/learn-blockchains-by-building-one-117428612f46
Copying over all this content is too much.
But this is a good start.
The code is on Git Hub.
Go crazy!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Reflect and connect.
Have someone give you a kiss, and tell you that I love you, Mom.
I miss you so very much, Mom.
Talk to you tomorrow, Mom.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Days ago = 1020 days ago
- Bloggery committed by chris tower - 1804.19 - 10:10
NEW (written 1708.27) NOTE on time: I am now in the same time zone as Google! So, when I post at 10:10 a.m. PDT to coincide with the time of your death, Mom, I am now actually posting late, so it's really 1:10 p.m. EDT. But I will continue to use the time stamp of 10:10 a.m. to remember the time of your death, Mom. I know this only matters to me, and to you, Mom.
No comments:
Post a Comment