A web-based demonstration of blockchain concepts.

Overview

Blockchain Demo

A web-based demonstration of blockchain concepts.

Blockchain 101 - Demo

This is a very basic visual introduction to the concepts behind a blockchain. We introduce the idea of an immutable ledger using an interactive web demo that is available here:

http://anders.com/blockchain/

Setup

Get the code:

git clone https://github.com/anders94/blockchain-demo.git

Install dependencies:

cd blockchain-demo
npm install

Run the server:

npm start

OR

./bin/www

#For windows: if the above command didn't work, use this (make sure you have Node.js installed in your system):

node ./bin/www      

Point a web browser at the demo:

http://localhost:3000

Setup using Docker

Get the code:

git clone https://github.com/anders94/blockchain-demo.git

Run the Docker setup:

cd blockchain-demo
docker-compose up -d

Point a web browser at the demo:

http://localhost:3000

Optional Configuration

You can adjust the "number of zeros" required by the demo by editing the first two lines of public/javascripts/blockchain.js.

Because there are 16 possible characters in a hex value, each time you increment the difficulty by one you make the puzzle 16 times harder. In my testing, a difficulty of 6 requires a maximumNonce well over 500,000,000.

If you adjust the difficulty above 4, blocks will show up as not mined because the demo data assumes 4 zeros for a signed block. For example, on the http://localhost:3000/block page with a difficulty of 6, the first nonce that works is 8719932 yielding a hash of 000000669445c22167511857d8f3b822b331c3342f25dfdcb326e35c1a7aa267. This gets out of hand fairly quickly though. Here's some time estimates at the various thresholds.

digits nonce time estimate
4 500,000 15 minutes
5 8,000,000 4 hours
6 128,000,000 3 days
7 2,048,000,000 a month
8 32,768,000,000 2 years
9 524,288,000,000 30 years
10 8,388,608,000,000 481 years
11 134,217,728,000,000 7,690 years
12 2,147,483,648,000,000 123,036 years
13 34,359,738,368,000,000 1,968,581 years
14 549,755,813,888,000,000 31,497,291 years
15 8,796,093,022,208,000,000 503,956,662 years

In the production bitcoin blockchain, block 458,091 has the hash digest 00000000000000000000011246f099d94f91628d71c9d75ad2f9a06e2beb7e92. That's 21 zeros in a row! That one block would take this software approximately 8,454,989,768,407,765 years to mine.

Public Private Key Demo

The 2nd part of the 101 session:

Send Thanks

Bitcoin gratefully accepted: 1K3NvcuZzVTueHW1qhkG2Cm3viRkh2EXJp

Issues
  • Difficulty Target

    Difficulty Target

    Hi Anders, are the 4 zeros at the beginning of the hash the so-called difficultiy target, which must be found by the mining?

    Thanks for the great work. I wait eagerly for the continuation of your demo.

    Best regards, Arne

    opened by Arne-Pfeilsticker 14
  • Error running in container

    Error running in container

    I'm getting the following error wher trying to run the demo in a container using docker-compose up -d command ': No such file or directory Is it working for you? Thanks.

    opened by kpantos 5
  • Blockchain and Distributed Tab Chains Behave Differently

    Blockchain and Distributed Tab Chains Behave Differently

    I noticed, when experimenting with your excellent demo, that the chains on the blockchain and distributed tabs behave differently.

    For example, on the blockchain tab when you modify the data field on the second block, which breaks the hash signature as expected, the next block in the chain reflects the proper (broken) hash in the Prev field. Also, when you mine the current block again, generating a good signature for the block, the next block in the chain (and all following) reflect the newly generated hashes in the Prev field as well. This works as expected.

    However, on the Distributed tab, which to my thinking should behave identically, just with three parallel blockchains, the next and all following blocks do NOT update the Prev value to reflect reality. This means you would need to carry those values forward manually, where I should just be able to kepp clicking mine on successive blocks to get one of the chains to be divergent from all of the others (while still being internally consistent).

    After cloning and testing it out I believe changing line 55 in the distributed code with the following diff would fix it:

    https://github.com/anders94/blockchain-demo/blob/master/views/distributed.jade#L55

    $ git diff
    diff --git a/views/distributed.jade b/views/distributed.jade
    index 8793610..49cb601 100644
    --- a/views/distributed.jade
    +++ b/views/distributed.jade
    @@ -52,7 +52,7 @@ block content
               var l = Ladda.create(this);
               l.start();
               setTimeout(function() {
    -              mine(block, chain);
    +              mine(block, chain, true);
                   l.stop();
                 }, 250); // give UI time to update
             });
    

    I think this also fixes the token page which does not currently break signatures if you modify a value in the data block.

    opened by grempe 4
  • Coinbase mining changes data instead of nonce

    Coinbase mining changes data instead of nonce

    Hi !

    This work is a amazing idea :)

    I'm struggling with the coinbase tab. I change, for instance, the initial amount of coin received by Anders. As the block chain is broken, i click Mine, and, instead of modifying the nonce value, the initial amount of coin is reset to 100.

    IMHO, it should be much more interesting to only tweak nonce value (as shown in the video), allowing one to break the blockchain to understand its interest in case of coinbase implementation.

    Tested on Firefox 51.0.1, 64bits, fedora 24.

    opened by Aluriak 4
  • npm WARN deprecated messageformat@0.3.1: Package renamed as '@messageformat/core'

    npm WARN deprecated [email protected]: Package renamed as '@messageformat/core'

    Getting the below error on install npm: npm WARN deprecated [email protected]: Package renamed as '@messageformat/core', see messageformat.github.io for more details. 'messageformat' will eventually provide a polyfill for Intl.MessageFormat, once it's been defined by Unicode & ECMA. npm ERR! Linux 5.4.0-104-generic npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" npm ERR! node v8.10.0 npm ERR! npm v3.5.2 npm ERR! code EMISSINGARG

    npm ERR! typeerror Error: Missing required argument #1 npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3) npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22) npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12) npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7 npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50 npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12 npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5) npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7) npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20) npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50 npm ERR! typeerror This is an error with npm itself. Please report this error at: npm ERR! typeerror http://github.com/npm/npm/issues

    npm ERR! Please include the following file with any support request: npm ERR! /home/dibs/Desktop/Blockchain_WebDemo/blockchain-demo/npm-debug.log

    Looking for a possible fix for this issue. Is this an issue with the NPM itself to some specific version?

    opened by indiancharlzz 3
  • Pasting Values Does Not Immediately Change the Other Blocks

    Pasting Values Does Not Immediately Change the Other Blocks

    As the title states, there is a problem when pasting values in the Block, Blockchain, and Distributed tabs (the tabs I've been working with). This problem seems to be the case only for when a paste is used through right-click. This problem was tested on both the latest versions of Chrome and Firefox. This seems to be a simple fix as you can type something on the keyboard and backspace giving the correct result, but this is nonetheless something that could be fixed.

    opened by SamHartIvy 3
  • Valid Balance and more...

    Valid Balance and more...

    First of all : Great project !

    Question #1: Please details how transactions are validated (there are sufficient funds) In video you mentioned if user A received in previous block $10 than in the next one can transfer $2. What if user A besides receiving $10 also transfer those $10 in previous block?

    Question #2: Please explain how peers synchronize their chains?

    Question #3: Do you plan to add the functionality to add "Blocks"?

    Thanks

    opened by zverbatim 3
  • Changes not detected properly

    Changes not detected properly

    In your demo under the "Tokens" section, I can change the first row of each Tx: segment without invalidating the hash. I don't think this is how it is intended, right?

    opened by AuspeXeu 3
  • app.js is not running

    app.js is not running

    As i18n does not work, I have commented on it in the app.js file, but when executing the program with the node app.js. Nothing happens, just app.js seems not to be running on the server.

    var express = require('express'); //var i18n = require('i18n'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser');

    ** next section ** /i18n.configure({ locales:['en', 'de', 'es', 'fr-CA', 'hi', 'ja', 'ko', 'nl', 'pl', 'pt', 'zh-CN', 'hu'],
    directory: __dirname + '/locales' });
    /

    opened by yordanjose 2
  • Error i18n and RUN app.js

    Error i18n and RUN app.js

    ** RUN app.js ** [email protected]:~/Documentos/blockchain-demo$ node app.js module.js:549 throw err; ^

    Error: Cannot find module 'i18n' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at Object. (/home/myuserpc/Documentos/blockchain-demo/app.js:2:12) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

    ** INSTALL i18n ** [email protected]:~/Documentos/blockchain-demo$ npm install i18n --save npm ERR! Linux 4.15.0-20-generic npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "i18n" "--save" npm ERR! node v8.10.0 npm ERR! npm v3.5.2 npm ERR! code EMISSINGARG

    npm ERR! typeerror Error: Missing required argument #1 npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3) npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22) npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12) npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7 npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50 npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12 npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5) npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7) npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20) npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50 npm ERR! typeerror This is an error with npm itself. Please report this error at: npm ERR! typeerror http://github.com/npm/npm/issues

    npm ERR! Please include the following file with any support request: npm ERR! /home/myuserpc/Documentos/blockchain-demo/npm-debug.log

    opened by yordanjose 2
  • How to run behind a reverse proxy

    How to run behind a reverse proxy

    What would it take to run this behind a nginx reverse proxy?
    I tried this at first, but I guess there is a problem with translating the address between the layers, so all i get is the base html-template.

    location /btc {
        proxy_pass http://localhost:3000;
    }
    

    Do i have to edit something in the code, or do you know of some other parametres i can use in the nginx-config?
    I'm running the app in a docker container, built from the dockerfile in the source code.

    opened by metasikander 2
  • Block difficulty configurable via queryString for blocks tab

    Block difficulty configurable via queryString for blocks tab

    I am providing difficulty for "blocks" tab from query string. This required minimum change in current code and it will help explain concept of difficulty while introducing nonce for a block.

    If you want then I can take this concept forward for all tabs.

    opened by MrHmP 1
  • pt-br docs

    pt-br docs

    Hello @anders94!

    I would like to say that I loved your blockchain-demo. So, I decided to contribute to it, creating and sharing with my Brazilian friends, docs in our language (pt-br). I created these docs using asciidoctor. I created a GitHub Page where, at this moment, there is a document. Also, there is a PDF version of this document (built from the same sources). If you like it, I would love to participate in the project by offering him these documents.

    This week I'm working on produce some videos (in Brazilian Portuguese). They will finish a blockchain presentation that I made to a Java User Group here, in Brasil. Then, I will publish they to YouTube and, ater that, I'll create closed captions for it, in English. I have some ideas about how can I improve the project. Some of them involve updating the code you wrote. I would like to continue to develop the project, along with you.

    Thank you!

    opened by paulojeronimo 2
Owner
Anders Brownworth
Slinging code and flying helicopters.
Anders Brownworth
Proof of History in Golang. Taking key concepts from the Solana whitepaper and providing examples in Go

Proof of History - Concepts in Go ________ ________ ___ ___ |\ __ \|\ __ \|\ \|\ \ \ \ \|\ \ \ \|\ \ \ \\\ \

Ben Duncan 7 Jul 20, 2022
Go language implementation of a blockchain based on the BDLS BFT protocol. The implementation was adapted from Ethereum and Sperax implementation

BDLS protocol based PoS Blockchain Most functionalities of this client is similar to the Ethereum golang implementation. If you do not find your quest

Yongge Wang 0 Jan 1, 2022
A blockchain-based demo that shows an alternative strategy for ensuring data and log integrity on aircraft

A blockchain-based demo that shows an alternative strategy for ensuring data and log integrity on aircraft. (Coded in less than 24 hours for GunnHack)

sckzor 0 Feb 6, 2022
Powerful Blockchain streaming data engine, based on StreamingFast Firehose technology.

Substreams - A streaming data engine for The Graph - by StreamingFast DEVELOPER PREVIEW OF SUBSTREAMS Think Fluvio for deterministic blockchain data.

StreamingFast 39 Aug 9, 2022
DERO Homomorphic Encryption Blockchain Protocol

Homomorphic encryption is a form of encryption allowing one to perform calculations on encrypted data without decrypting it first. The result of the computation is in an encrypted form, when decrypted the output is the same as if the operations had been performed on the unencrypted data.

null 98 Aug 10, 2022
A simplified blockchain implementation in Golang

A simplified blockchain implementation in Golang

Ivan Kuznetsov 3.5k Aug 10, 2022
DERO: Secure, Anonymous Blockchain with Smart Contracts. Subscribe to Dero announcements by sending mail to [email protected] with subject: subscribe announcements

Welcome to the Dero Project DERO News Forum Wiki Explorer Source Twitter Discord Github Stats WebWallet Medium Table of Contents ABOUT DERO PROJECT DE

null 274 May 22, 2022
run ABI encoded data against the ethereum blockchain

Run EVM code against a database at a certain block height - Note You can't run this against a running geth node - because that would share the db and

Edgar Aroutiounian 60 Nov 11, 2021
Go module for the Cardano Blockchain

cardano-go cardano-go is both a library for creating go applicactions that interact with the Cardano Blockchain as well as a CLI to manage Cardano Wal

Alonso Villegas 30 Aug 10, 2022
chia-blockchain some function implement in golang

gochia chia-blockchain some function implement in golang Package bls-signatures implement blspy Usage? Now we can use it to generate plot memo and id,

Kure 8 May 27, 2022
Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint.

Frontier Chain Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint. Setup Initialize the blockchain with one validator no

Frontier 12 Jul 12, 2022
Implementing blockchain using Golang ✔️

Implementing blockchain using Golang ✔️ Keys The Blockchain uses ECDSA (224 bits) keys.

null 7 May 24, 2022
Gochain is a Blockchain written in go

gochain gochain is a proof-of-work blockchain written in go. Features Proof-Of-Work Persistence CLI Transactions Addresses Merkle Tree Network How to

Jonas Ampferl 8 Jul 14, 2022
LINE Financial Blockchain forked from gaia

LFB(LINE Financial Blockchain) This repository hosts LFB(LINE Financial Blockchain). This repository is forked from gaia at 2021-03-15. LFB is a mainn

LINE 31 Aug 4, 2022
utreexo blockchain skeleton

sunyata sunyata is a blockchain skeleton. It implements a minimally-functional proof-of-work blockchain, including consensus algorithms, p2p networkin

The Sia Foundation 18 May 24, 2022
OmniFlix Hub is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

OmniFlix Hub is the root chain of the OmniFlix Network. Sovereign chains and DAOs connect to the OmniFlix Hub to manage their web2 & web3 media operations (mint, manage, distribute & monetize) as well as community interactions.

OmniFlix Network 34 Jun 27, 2022
A plugin that turn hashicorp vault into blockchain wallet.

dq-vault - Hashicorp vault BTC/ETH plugin This vault plugin stores a user's mnemonic inside vault in an encrypted manner. The plugin uses this stored

Deqode 8 Jul 28, 2022
Tools to help teams develop smart contracts on the Cardano blockchain

toolkit-for-cardano toolkit-for-cardano simplifies the development of Cardano smart contracts by providing teams with frequently needed tasks: Build T

SundaeSwap Finance 139 Aug 1, 2022
Yu is a highly customizable blockchain framework.

禹 Yu is a highly customizable blockchain framework. 中文文档 Overall Structure Introduction By using Yu, you can customize three levels to develop your ow

null 24 Jul 19, 2022