Blockchain 101 - A Visual Demo
This is a blockchain demo. We're gonna do this in a very visual way, though. We're gonna make it very easy to understand by stepping through the key pieces of what a blockchain is in a visual way.
But before we get started, we need to take a look at this thing that we call a SHA-256 hash. Ok? A hash, this is one of them right here. A hash looks like a bunch of random numbers, and essentially what it is, it's a fingerprint of some digital data. It just so happens it's a fingerprint of whatever I type in this box. So if I type my name "Anders" into this box, you see that the hash has changed. Matter of fact, it changed every time I typed a letter, right? So I'm going to go back. So it says "Anders". Ok. So this is the hash of the name "Anders", all lower case. It starts with 19ea, right?
Ok, so if I delete that and I go again and type "Anders" again, you can see it starts with 19ea, the same exact hash. In that sense, it's a digital fingerprint of this data. Whatever data is here, every time you type exactly the same data, you get exactly the same hash. I can type anything I want. So I can, you can have nothing like this, you know, e3b0. That's the hash of nothing. Or you could type tons and tons of stuff. A matter of fact, you could put like the Library of Congress in here and you would get a hash.
The interesting thing about it is regardless if there's a tiny amount of information, no information, or the entire Library of Congress, you're always going to get a hash that is this long. This many characters; you're not going to be able to pre-guess what this is. You kind of have to put the Library of Congress in here to figure out what the hash is. But you'll always get exactly the same hash regardless of how many times you put exactly the same information in.
So what I'm going to do is extend this idea of a hash into something that we're gonna call a block. Alright, so let's take a look at a block. So this is a block, and it's exactly like the hash. It's just that the data section, I've broken out now into three sections. One called "block". This is just some kind of a number, this block number 1. A nonce, which is just yet another number. We'll go into what that is in a second, and then just some more data. Just very similarly to the way that we had it before. However, the hash of this, which includes all of this information up here, is down here and it begins with four zeros. You see that? It's a relatively unusual hash. You know, most of them are not really going to start with four zeros like that, but this one happens to.
And because it does, totally arbitrarily, I'm going to say that this block is signed. Ok, so what would happen if I were to change any one piece of this information? Let's say if I were to type something here, right? The hash is going to change. And what's the chance of that, if I type letters, this hash is going to start with four zeros? Pretty low, it's probably not, right? So let's see what happens when I do that. I'm just going to say "hi". Look at that! Right, this hash does not start with four zeros. And so the big background here has turned red. So now you know that this block with this information in it is not a valid or a signed block. Ok, and that's where this nonce comes in. This nonce is just a number that you can set to try to find a number that fits so that this hash starts with four zeros again.
Alright, so how do we do that? Well, let's start with one that starts with... now it's 32, so that's not one. Let's try two. FF, now 3, 4, 5, 6. So you get the idea. Like, I could sit here all day... there's one that starts with 0. I can sit here all day typing these numbers and trying to figure out one that actually is going to hash out to something that starts with four zeros. That would take a long time.
So here I have my little mine button. I'm sure you've been wondering what happens if I press that. So what's going to happen when I press this mine button is it's gonna run through all the numbers from 1 all the way up to try to find one where the hash starts with four zeros. This process is called mining. Let's do it right now. Now it's checking all of the numbers from 1 all the way up. Now it's stopped at 59,396, and that one just happens to hash out to something that starts with four zeros, and it satisfies my little definition of what a signed block is. Ok, so that's a block.
Now, can you tell me what a blockchain is? It's probably just a chain of these blocks. Well, how do you put them together? Let's do that. Alright, so here's my blockchain. Block number one has some kind of a nonce just like before. There's some data area too, but then it has this previous. Here is a bunch of zeros. Let's roll forward. So this is block two and block three and four. This blockchain has five blocks on it, right? The previous here starts with 0000ae8, right? Is this number ae8. And then this previous, you know, b90 is this one over here, b90.
So you can see that each block points backwards to the one before it. You remember that that first block over here? There actually is no previous, so it's just a bunch of zeros; it's actually just a fake number. Ok, so just like we did before, what happens if I change some information here, right? It's going to change the hash of this block and it's going to invalidate it. Right now, let's try that. So I'm going to type "pie" again. Sure enough, that block is invalid. Alright, just as we assume.
But what would happen? I'm going to fix that now. We'll go back to something that works. What would happen if I changed something in this block? Right? It's going to change this hash, but this hash gets copied up to this previous, so it's going to change this one too, right? So it should break both blocks. So let me try typing "hi" in there and sure enough, alright? So we can go back as far as we want, you know, to some point in the past and break that block, and it will break all the blocks since then. Everything before, still green, but this one is red.
If I wanted to, you know, change something in this blockchain, I could just go over to block number five right here. We could change it. I'll put "hi" and then we could remine it, you know, and pick a different nonce. We'll do that right now, and we could essentially alter the chain. So we've done it so that we should be good down, right?
Alright, well, what happens if I go back in time to here and I break it? Here, now I have to mine this block, which will pick a nonce that makes this block hash out to four zeros. If we can find one, sometimes it takes a while, because it's gotta run through a lot of... there it is! It found one at 138,000. Alright? But this one is still broken because although this one starts with four zeros, adding the four zeros with different stuff up here still makes this block hash out incorrectly, so I also have to mine this block. Alright? And that takes some amount of time. That one was a little bit quicker, and then I have to mine this block to fix it.
Alright? So what we're showing here is that if I go and change this last block, all I have to do is remine this block. If I go way back in time to back here and I make a change like that, I'm going to have to mine this one, this one, this one, and this one. So the more blocks that go by, the more blocks in the past that we are, the harder and harder and harder it is to make a change. And so that's how a blockchain is going to resist mutation, resist change.
Ok, so now you, like, identify if I do this in this block here. You can see that I've changed it to "hi," and I remine it; blah, blah, blah. How would I know that my blockchain has been remined? Alright, let's take a look at that. I'm gonna hit this little distributed thing. So now we have a just distributed blockchain. It looks exactly like the last blockchain. Ok, up to five, but this is peer A, the first peer. If you go down here, you can see here is peer B, and it happens to have an exact copy of the blockchain. There's actually also a peer C down here. Right? This could go on forever. There are many, many peers out on the internet, and they all have a complete copy of the blockchain.
So in this case, if I look at this hash, it's 0000e4b. Alright? If I go down to this one, I notice it also has e4b. If I go down to this last one, it has e4b. So they must be identical, and I'm going to demonstrate that by going here and typing something. I'll type "hi" again, and then I will remine this block. I've got some other number, now let's put some other number up here. So I should be able to mine this block.
Ok, now all the chains are green, right? They're all green. However, this chain says the last hash is e4b; the bottom one says that too, e4b, and this middle one here says 4cae. So I know just by glancing at this one little hash that something is wrong in this blockchain. Even though all of the hashes start with four zeros, I know that this one is different, and it's different because I have two. It's essentially two against one. We are a little democracy here, right? This guy argues that it's e4b, this guy argues that it's 4ca, and this one is e4b. So e4b wins!
So that's how a completely distributed copy, having a copy on many different computers, they can all very quickly see if all of the blocks are identical. Remember, blockchains can have, you know, 4, 500,000 blocks very easily. So rather than checking through all of them, all you really have to do is look at the hash of the most recent one. You can see that if anything in the past, anything way back here was altered, you can tell by looking at the last block in this chain. You know, it's going to hash out to something that doesn't start with four zeros and looks very different from what the hashes on the good chains are.
Ok, so that's a blockchain. That's the entire thing. There is no more to it than that. But it's kind of not really useful because we don't have something in this data area that means anything. I keep typing my name or "hi" and that's kind of that sort of irrelevant information. So what we really want is a token. So let's do a token on our blockchain.
Alright, now look at this. So I have this token, just totally arbitrarily, I'm calling these, I guess, dollars. Right? So we have twenty-five dollars from Darcy to Bingley, four dollars and twenty-seven cents go from Elizabeth to Jane. You get the idea. It's basically, there are all these transactions that are happening, and I've just replaced the data with these transactions.
Just like we saw before, you know, so there's multiple blocks here. This one has more transact... it doesn't matter how many transactions there are. There can be many, or there can be few, or none. If we keep going forward here, just like we saw before, if we go down and we notice we have all these other copies of the same blockchain. Right? So now here's where the immutability is important. If I change something back here, you'll notice that this is, you know, a7fc blah blah blah something. It's something different than what's down here.
So in this way, I mean, it's very important that if I were to go back in time and change some value that we would notice. It's very important with money that you don't lose track, and that's the whole point of using a blockchain here. This is the whole point of resisting any kind of modifications, you know, of things that have happened in the past.
So that's the reasoning behind having using a blockchain to remember tokens. Now, one thing I would mention here is that we're not listing, you know, Darcy has a hundred dollars and he's giving twenty-five of it to Bingley. The only thing we're saying is Darcy gives twenty-five to Bingley. We're not remembering a bank account balance; we're only remembering money movements.
So this begs the question: "Does Darcy have $25?" Well, we have a problem here in this version of the blockchain: we don't actually know if Darcy has $25. So let's look at a coinbase transaction. So if we look back here, a coinbase, we're going to add a coinbase transaction to our blocks. And this is very similar to what we've seen before, but we're just adding a coinbase at the top.
And what's that saying is we're going to invent a hundred dollars out of thin air and give it to Anders. And there's no transactions in this block because nobody had any money previous to this. In the next block, another hundred dollars comes out of nowhere and goes to Anders. I'm a fan, I love it, right? I'll take a hundred bucks.
Now we have some transactions. You can see that they're all from Anders. They're all from me because I'm the only one who has any money at this point. So I'm sending ten of my dollars to Sophie. Do I have ten dollars? Yeah, I do. I look back and I see that this coinbase transaction has given me a hundred, so I have at least 10. I can send it on, and you add all these up, and they don't go over a hundred. It follows sort of a basic rule of a currency that you can't invent it out of thin air. You can't create money out of thin air; its dispersion is controlled.
So now if we look at this blockchain that we've created and we zip forward in time, we notice that we see that Jackson is giving Alexa two dollars. And so does Jackson actually have two dollars to give to Alexa? Well, we go back a block before. We see that Emily had gotten ten dollars from Anders and gave ten to Jackson, and so Jackson does have the money.
So we can just go backwards and find that out. That's actually one of the benefits of having a previous here. It's easy to go backwards. We just look for the block that looks like that, that has that hash, and here it is right here, right? So it points two blocks back in time and allows us to trace the provenance of any coin that we want.
So that's a basic blockchain, and we're running a currency on top of it. And as you know, blockchains are... there are many copies; everybody has a copy of it. So if we mutate, you know, this and make it six dollars, these go invalid. It does not agree with these blockchains down here, these copies of the same blockchain down here.
So this resists tampering, which is what you want for a currency. It works very well for things that are small and transactional like this. Go ahead and fix that, and they're just a very efficient way to handle agreement on what has happened in the past, as kind of this immutable history that goes down with time. So that's a basic blockchain and a token on it.
There were glossing over some main points, but if you dig into the demo and click through these things and play around with it, you get a better and better idea of how this works. There will be a part 2 where we go into a little bit more detail about how the transactions are created. Till then.