Sessions is temporarily moving to YouTube, check out all our new videos here.

Build Your Own Blockchains in JavaScript for Fun (and Profit)!

Gerald Bauer speaking at viennaJS in September, 2017
Great talks, fired to your inbox 👌
No junk, no spam, just great talks. Unsubscribe any time.

About this talk

Gerald will explain what blockchains are and how they work, and show how to build them in JavaScript.


So, I'll try to do 25. I have 30 slides. I'll try to go fast. So, how can you turn like, this is the upcoming Schilling, Schilling on the blockchain. How can you turn this number into gold? But not gold, euros or dollars. So, anybody a guess how do you do it? So, how do you turn it gold or into euros? You put it on the blockchain. And what is the blockchain? The magic blockchain, blockchain, blockchain? So, decentralised payments, or decentralised central banking. A translation is fuck the banks. So for decentralised. And so what's a blockchain? So a blockchain, distributed database, hyper ledger book, or a consensus with proof-of-work, digital lottery, a central bank? Why not open not just your own bank, but way better is to open your own central bank. And it's a solution to the Byzantine-Generals problem. So yes, yes, everything, that's what the blockchain delivers. And am I crazy? And the proof of the pudding is, is the pudding good? It's an English proverb, you have to eat it. Does it really work? And so the proof of the pudding of the blockchain is Bitcoin, if anybody knows Bitcoin. So, the Bitcoin is on the blockchain, and it's a success story, so that's the proof of the pudding. It works, and the first actual payment of Bitcoin was in May 2010. And for 10,000, there was like a challenge, who is going to deliver two pizzas for 10,000 Bitcoins? And then, some guy, you know, the estimated worth was like $40 of the Peppy Pizzas, delivered two pizzas. And this day is now known as the $20 million pizza day for celebrating how the birthday of Bitcoin. And so the question is, do you know how much is a Bitcoin worth today? One single-- About 3,000 So it's like 4,000, and anybody want to do the calculation? 10,000, if you buy a pizza for 10,000 Bitcoins, that's the chart. So, today it's kind of, it's growing. So, there's like $80,000 million worth of Bitcoins. 80 billions out of nothing. So it's of course, it's all an illusion. So if your invested in Bitcoin, sell now. It's just, you're going to, yeah. So, let's build your own blockchain, you know? Blockchain, blockchain, blockchain technology, you have to hire consultants, and you have to, you know a Crypto God there was in Berlin. We are looking for a full stack blockchain developers like Crypto Gods, JavaScript ninja, but it's really, you know? You can't build it from scratch. And now I have to switch to the Austrian government. The Austrian government has started in August an initiative. It's called Blockchain Austria, and the Minister of Economics Affairs. So, this is in German, but this technology is the new internet. It's a revolution, and if you don't use it now you will die, you know, because your business is, This is the Minister telling you, and it goes on. Blockchain, blockchain, blockchain, blockchain. Austria, every Austrian needs to get on the blockchain. It's your duty. And so, let's have another one. You know, there's no more secure way to and no transparent for data and payments. And again, Harald Mahrer, he is the Bundes minister, so it's an official. It's not a joke. So blockchain, blockchain, blockchain. So what are these guys? So that's the blockchain in JavaScript. 20 lines, maybe I'm lying, So it might just be like six lines. It's a data structure, so can you imagine it's starting like HashMap Austria? Or linked list Austria. Their initiative will revolutionise the internet. And so, what's a blockchain? And this blockchain is on Open Blockchains. Awesome blockchains. And the important part of blockchain is the name. It's a chain of blocks. And so you define a block, and the block has an index because it's a chain. At the index zero, one, two, three, four, five. Then it has a timestamp because the block, you add one block, you add the next block, and the next block. And every block has to go in time after the next block. Then you have your data which might be the Schilling, or it might be the Bitcoin transactions. And the important part, this is the link. The link is, you're using an crypto hash. So that also sounds good. Don't say hash, always says crypto hash. You know, crypto, it's like cyber security. - [Man] You can't talk So when the crypto hash for normal people, it's called a dig-il-del-for, digital transformation and digital fingerprints. It's a name for crypto hash. And that's the blockchain. And to add more, let's do the mining, to mine for blocks. So how do you mine for a block? So if you create a new block, you have mined a new block, that's how mining works. And this will take 0.2 milliseconds. And you have a new block, but how much is this block worth? So probably in a couple years, this is more worth than your Bitcoin block. And so you create the first block. This is a special block that's the Big Bang that starts it all. And then you just add one block after the next. That's why the tagline is the revolution is built, so the new internet's a block at a time. You add the first block, and then if you add the next block, you have to pass in the previous block, and that's how you build the blockchain. And so that's in there with four blocks. And if I do console.log to print, how does this blockchain magic look? So the first one doesn't have the genesis, the Big Bang, like this is God, you know. Who created the previous hash? How did it all started? Who created all this crazy stuff? But all the others, there's the chain. And the chain is the hash. So these hash do we have to match, and then it goes on in time. One, two, three, four, five, six, seven, eight, nine. The magic blockchain. And that's the important part. It's not linked linked Austria, linked list Austria, but it's blockchain Austria. So it's almost a linked list, but the main difference, and that's really the fantastic thing, it has the crypto hash. And with the crypto hash, you cannot change. If you change the data, your fingerprint is going to change. And if you add more blocks and more blocks and more blocks, the blocks up, they are getting more and more secure. So you can easily fake the last block, but if you add more and more blocks, every block helps to build the last block and make it more secure, so that's the whole magic. Sometimes if you post it online, they tell you, you know, this is not a blockchain. Bitcoin is using something, mining proof-of-work. And consensus, you know. A blockchain needs proof-of-work and consensus. It sounds like wowbig work. It's like digital transformation. What does it all mean? And so the proof-of-work, all it means, it's a lottery and you have to find the lucky number. And so, to have a lucky number, how it works is if you add a block to the Bitcoin blockchain for example, so Bitcoin blockchain adds every 10 minutes. So that's a typo. So the Bitcoin blockchain adds a block every 10 minutes. And the guy or the girl who adds the new block gets, it was 25 Bitcoins, but now it was half. You only get 12.5 and in four more years, it's again half. So you get 12.5 Bitcoin for adding a block. And all you have to do is you have to find the lucky number. And how can you make it harder to calculate the hash so that it's a lottery. So the guy or the computer who finds the lucky number for the hash can add the next block and wins the lottery, which means he gets this 12.5 Bitcoin. And then, the lottery starts again every 10 minutes. So every 10 minutes you get a new lottery. And because it's a secure hash, Bitcoin for example, I'm using in the example you have seen, so that's a quiz. What does SHA, what's the acronym? What does it stand for? Super High Aperture, Sweet Home Austria, or Still Hacking Away, Secure Hash Algorithm. Any guess, A,B,C,D? So it's Secure Hash Algorithm is the answer for the random hash. And so it's secure and the hash, the 256, is 256 bits. And it's a number in hexadecimal. If you compute it, it's always a random number. And it always has the same lengths. But the thing is, if you change the content, that transactions only one letter, it completely changes. And basically it's to make it secure. It has to be random. And now the great part is conspiracy. So this gift to the world, the National Security Agency of the United States, they invented, or the secure hash algorithm is invented and designed by the National Security Agency. So you can rest assured it is secure. And so the important part, it's random. And so random is like, for the lottery. And so how it works, your hash has to start, let's say, with 10 servers. And so you have to calculate, and how can you calculate a hash? Because if you calculate, use the transaction, you always get the same hash. So you use something called the lucky number, and then the lucky number 123456, and every time you calculate with another different lucky number, you get another hash. But the hash has to match and start with 000. And now the question is like how many, on the real Bitcoin network, how many calculations do you have to do to find the lucky number? That's the version in JavaScript to find the lucky number. It's just a loop. The nonce is the lucky number. It just has to match 00, which is on average 256 possibilities. But anybody guess how many calculations do you have for an Bitcoin block today? How many? Again, it's like 25 quadrillion ta-tro-li-ums or whatever. So it takes 20 minutes for super computers that need 20% of the energy of Great Britain. That's why the Bitcoin, you know. If you run in circle on, do you think you are creating value? Is the Schilling getting more worse if you run around on? And so if you calculate this crazy hash numbers here, and it's using 20% of the like. Anyway one single transaction is the energy, and you cannot if you compete today, like special design hardware and super low energy braces. But the point is for a blockchain, you don't need the proof-of-work. The Bitcoin blockchain is kind of the worst database. The energy consumption is kind of lunatic. And it's not mining, you know. They are calling it mining like in a goldmine, but it's not really mining. But you might call it like you're running around in circles on, and then is it really, what you get, is it gold? I'm giving away 100 Schilling on the blockchain. And you know, if you get in early, you have seen the Bitcoin, don't laugh. We will celebrate the Schilling Day when we hit the euro. Because the Bitcoin was $1, and then it was a big milestone. Wow, that's a bubble, you know? Bitcoin is $1 and then it hit the price of gold, which is like more than $1,000. And so the Schilling on the blockchain, when will it hit like 20 years or 30 year, like more value than the euro? Anyway, anybody knows the tulip mania bubble in Holland? What year, like 1753, A,B,C,D? - [Man] E and So it was the first speculation bubble, tiny. It is B, 1637, the Golden Age of Holland, and now the most expensive tulip, what's the name of the most expensive tulip? - [Man] C. Admirals of admirals of admirals, because they were the shipping empire. Admiral van Eijk, Semper Caesar, and Semper Augustus is the red-white tulip. So I have a project that is called to study how to make your own blockchain because the Schilling is not international. So I have a second project that's called Tulips on the Blockchain. And I'll show you how to add transactions to your blockchain. And it's always good, a real world example from 1633. And there's the Semper Augustus. And we have some miners, it's like Dutchgrown and Bloom and Blossom, and Teleflora, they are the miners. And so how you put it on the blockchain? In three days, you can pick up your tulips. You have to buy tulips, tokens. And then let's go back here. But the funny thing is, yeah. So the quote from the website, people compare digital tokens to tulips. And you know, tulips come from the earth, but tulip tokens are from the blockchain. And you know, the blockchain is the new internet, the best technology in innovation since the internet. Ask the Austrian minister. Okay, so Tulips on the Blockchain, how do you add transactions? So you add the transactions from two, and in this case the quantity of the tulips, and then of course you say console.log. And you have transactions on the blockchains with the tulip hyperledger book. And that's how it looks, and again, the important part is the hash, the crypto hash. And the crypto hash links to the next block. And so it's on GitHub, so if you add the next block, you are mining tulips. But more fun, the Schilling. Every day a new lottery. So, if you want to get started, I have bundled up the blockchain in a note package. You know, there's IBM has the IBM enterprise blockchain. And I sent a letter to the Rechenzentrum Austria you know. I offer blockchain, you know. I have three versions, a JavaScript, a Ruby, and then this, so it's on npm. Blockchain Lite, npm instal. Easy to use, you know? And it has different block types, the basic and the proof-of-work. But that's npm instal, and you have blockchain technology. And you are laughing about this Schilling. So let me, a case study. The Dutch Gulden is life. So a guy started the Dutch Gulden. It was no joke. You see how the Schilling will start? You have to get in early because once you are too late, and any guess how much is the Dutch Gulden worth today? So that's the coin market. So the Dutch Gulden has now 40 million US dollars worth of coins out of nothing. In Germany, there's a guy who failed with the Deutsche eMark, so that's a moot. No one is buying the Deutsche eMark. Oh, let's try this one. So Schilling, it's on GitHub. Invest now, you know. Rock-solid Alpine Dollar cannot get any better. Yeah, so if anyone wants to get started, blockchains are fantastic. And so there's like, I don't believe in blockchains. There's also a good one here, reflection on blockchain. But blockchain, blockchain. And there of course, a favourite book, Blockchain, that's free. Blockchain for Dummies, IBM Limited Edition. It's a free download. You have to add the email. And the Mastering Bitcoin, Programming the Open Blockchain is a open book orbook, but in print. But free online on GitHub. And I've put together, if anybody's on GitHub, there's awesome, awesome, awesome. Everything is together is on the Awesome Blockchains page, and it's like, the organisation is called Open Blockchains with S. Because now there are many, not only the Bitcoin blockchain. There are many blockchains. You can create your own blockchain. And there's the Schilling, but there's the Awesome Blockchain page where you get all the links. Let's try this one. Yeah, the last one. A funny one is, you know, if anybody using Git? So you are on the blockchain? If anybody's going blockchain technology is okay. There's one guy, yep that's a joke. Explain to me how the blockchain is different from a Git repo. Because in the Git repo, the content is addressed by crypto hash, and you have, mer-kel three, yeah. - [Man] Oh. Okay, so that's, So let's go to this one. This was my answer to the minister. It's like let's start Git Austria Initiative. Like the open data is secure in Git. You can share documents codes, you know. You can start today, and keep calm and learn Git first, I send. And another one is like, there's the Rechenzentrum. They have potential analyse, like a strategy paper. With all the experts from Austria, and they have a great article like Austria and the Blockchain, what they are going to do. And they are the leading technology partner of the Republic of Austria. And so I sent them like, hello guys. I can deliver a blockchains free. Free downloads JavaScript, serve yourself, cheers. I didn't get any answer so far. Okay, so, thanks for, oh yeah, that's the, yeah thanks.