A web-based demonstration of blockchain concepts.

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

Owner
Anders Brownworth
Slinging code and flying helicopters.
Anders Brownworth
Comments
  • 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

  • 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.

  • 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.

  • 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.

  • 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?

  • 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.

  • 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

  • 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?

  • 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' });
    /

  • Error i18n and RUN app.js

    Error i18n and RUN app.js

    ** RUN app.js ** myuserpc@myuserpc-pc:~/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 ** myuserpc@myuserpc-pc:~/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

  • 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.

  • Account balance checking

    Account balance checking

    In the video (final Coinbase section), you mention that only Anders can transact to others in Block 2, because only Anders has a historical balance to transact from.

    It would be a great enhancement if this final Coinbase implementation also made blocks Red/invalid if there are any attempts to transact from a source with insufficient balance (or maybe a different color-code, like purple? to indicate a different kind of invalidity than the Red for incorrect hash chaining)

    (Another thought: maybe the "Mine" button is deactivated until the transactions are valid according to historical balances)

  • [Question] How does one calculate the max nonces limit?

    [Question] How does one calculate the max nonces limit?

    I am trying to make an Proof-of-work script myself, and i want the nonce limit to change dynamically with the difficulty. The example table shows that the difficulty 4 has a max of 500,000. How would i calculate the max, for a different difficulty?

    Thanks in advance

  • 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.

Proof of History in Golang. Taking key concepts from the Solana whitepaper and providing examples in Go

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

Oct 13, 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

Oct 14, 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)

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.

Dec 30, 2022
DERO Homomorphic Encryption Blockchain Protocol
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.

Dec 27, 2022
A simplified blockchain implementation in Golang

A simplified blockchain implementation in Golang

Dec 31, 2022
DERO: Secure, Anonymous Blockchain with Smart Contracts. Subscribe to Dero announcements by sending mail to [email protected] with subject: subscribe announcements
DERO: Secure, Anonymous Blockchain with Smart Contracts.  Subscribe to Dero announcements by sending mail to lists@dero.io 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

Dec 7, 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

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

Dec 1, 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,

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

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

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

May 24, 2022
Gochain is a Blockchain written in go
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

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

Dec 21, 2022
utreexo blockchain skeleton
utreexo blockchain skeleton

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

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.

Nov 10, 2022
A plugin that turn hashicorp vault into blockchain wallet.
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

Dec 7, 2022
Tools to help teams develop smart contracts on the Cardano blockchain
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

Dec 19, 2022
Yu is a highly customizable blockchain framework.
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

Jan 7, 2023