Coder Social home page Coder Social logo

0xs34n / blockchain-cli Goto Github PK

View Code? Open in Web Editor NEW
1.2K 65.0 169.0 3 MB

⛓️ A minimal blockchain command-line interface.

License: Apache License 2.0

JavaScript 100.00%
blockchain nodejs blockchain-technology blockchain-demos cryptocurrency cryptocurrencies javascript

blockchain-cli's Introduction



Blockchain CLI

A minimal blockchain command-line interface.

Gitter


screenshot

🎉 Features

  • 💎 Blocks with index, hash, data, and timestamp.
  • ⛏ Proof-of-work system.
  • ⛓ In-memory JavaScript array to store the blockchain.
  • ✅ Block integrity validation.
  • 📡 Decentralized and distributed peer-to-peer communication.
  • 🌴 Merkle tree implementation

📦 Installation

To install this application, you'll need Node.js (which comes with npm) installed on your computer. From your command line:

Source

You'll need Git to run the project from source. From your command line:

# Clone this repository
$ git clone https://github.com/seanseany/blockchain-cli

# Go into the repository
$ cd blockchain-cli

# Install dependencies
$ npm install

# Run the app
$ npm start

⚒️ Built With

🎫 License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details

🙏 Acknowledgments

  • This article written by Lauri Hartikka.
  • Original repo by Lauri Hartikka
  • Antony Jone's fork for refactoring.
  • Nick Fallon fork for PoW implementation.
  • Logo designed by Muammark / Freepik.
  • FAQ by /u/sheepiroth

ℹ️ FAQ

When or why I would use this?

You should use this if you want to build a bitcoin wallet, payment processor, or bitcoin merchant portal in javascript. You might also be interested in why decentralized networks or p2p applications are useful, or what advantages they have; this project seems like a good way to learn about that.

What is the block chain actually for?

The blockchain is for authorizing payments of a cryptocurrency between two peers without the need for a centralized 3rd party approving of the transaction. There are other uses of the blockchain which are more in line with the second point, digital signatures, but they are secondary to the main purpose of peer to peer transfer of value. Bitcoin is blockchain's killer app.

Why the hell should I care about the blockchain?

Blockchain facilitates trade over a network. Imagine a metal as scarce as gold with a magical property of "can be transported over a communications channel". This has implications with respect to individual rights, the world economy, and the way we monetize and transfer value at a level higher than bartering directly for goods.

Lately people are distancing themselves from the proof-of-work concept and are using blockchain to describe only the mechanism of signing a transaction as verification of sending an amount. Change "sending an amount" to almost anything else - authorizing a change in a ruleset, casting a vote for a politician, verifying a point of IoT data is authentic. Now add in the concept of a peer-to-peer network to this and you've eliminated a middleman that once existed, thereby improving the efficiency and reducing cost. In these cases, "blockchain" refers to the structuring of a program or database in such a way that it has no central point of failure while still providing all of the features expected. For example, augur and gnosis are decentralized prediction markets. Ethereum has implemented smart contracts which enable decentralized release of funds based on a gambling outcome.

blockchain-cli's People

Contributors

0xs34n avatar nblackburn avatar seanseany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockchain-cli's Issues

Fixed time display and hash display

fix time display

https://github.com/seanjameshan/blockchain-cli/blob/master/lib/cli/util/table.js#L26
the function 'toUTCString' should be changed to 'toISOString' (the toUTCString function will lose milliseconds that lead to sha256(block) different)
It's best to get rid of 'timeStamp/1000' but use timeStamp directly

fix hash display

https://github.com/seanjameshan/blockchain-cli/blob/master/lib/cli/util/table.js#L10
this line should be changed to 'colWidths:[20,66]' to show hash fully :
#13

make judgment more precise

https://github.com/seanjameshan/blockchain-cli/blob/master/lib/blockchain/index.js#L128
this line should be changed to 'return i >= this.difficulty;' ; the hash should contains at least difficulty zero

show mining time:

https://github.com/seanjameshan/blockchain-cli/blob/master/lib/blockchain/index.js#L111
before L111 while there should have a time:

var _beginTime = new Date();

after L116 spinner.clear(); there show have a tips:

console.log("Mining new block use time: ", new Date() - _beginTime, "ms")

Multiple Errors when attempting to install

npm-debug.txt

sudo npm install blockchain-cli -g
/usr/local/bin/blockchain -> /usr/local/lib/node_modules/blockchain-cli/main.js

[email protected] install /usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc
node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(undefined): https://node-webrtc.s3.amazonaws.com/wrtc/v0.0.62/Release/node-v57-linux-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v57 ABI) (falling back to source compile with node-gyp)
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build'
gyp ERR! System Linux 3.13.0-129-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64/wrtc.node" "--module_name=wrtc" "--module_path=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64"
gyp ERR! cwd /usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc
gyp ERR! node -v v8.4.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64/wrtc.node --module_name=wrtc --module_path=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64' (1)
node-pre-gyp ERR! stack at ChildProcess. (/usr/local/lib/node_modules/blockchain-cli/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:125:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:213:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:927:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
node-pre-gyp ERR! System Linux 3.13.0-129-generic
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/blockchain-cli/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc
node-pre-gyp ERR! node -v v8.4.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.36
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64/wrtc.node --module_name=wrtc --module_path=/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/speed/.npm/_logs/2017-09-06T13_24_14_797Z-debug.log

OS: ubuntu Ubuntu 14.04 trusty
Kernel: x86_64 Linux 3.13.0-129-generic
Uptime: 3h 1m
Packages: 4247
Shell: bash 4.3.11
Resolution: 1920x1080
DE: Gnome 3.9.90
WM: GNOME Shell
WM Theme: Adwaita
Radiance [GTK2]
, Radiance [GTK3]
Icon Theme: elementary-xfce-darker
Font: Cantarell 11
CPU: AMD FX-8350 Eight-Core @ 4GHz
GPU: GeForce GTX 750 Ti
RAM: 5535MiB / 24011MiB

"--harmony" flag in shebang breaks app.

The --harmony flag in the shebang line in this file is confusing my linux system, as it is treating node --harmony as a single executable file name:

~ $ npm i -g blockchain.js
~ $ blockchain
/usr/bin/env: ‘node --harmony’: No such file or directory

Considering anyone with a reasonably up-to-date Node installation won't need the harmony flag, it's probably safe to remove it and prevent this from being a problem for anyone - and, perhaps, encourage people to update their Node installations in the process.

Error when run blockchain

After I execute the command sudo npm install blockchain-cli -g,it occurs no errors.
But when I run 'blockchain' command,it ocuurs following errors:
image
What should I do?
My npm version is V5.4.2 and node version is V8.7.0

numerous npm install warnings

Failed when trying to npm install blockchain-cli -g
Then I tried git clone w/a local install
Mac / [email protected] / node v8.4.0

npm install
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ== integrity checksum failed when using sha512: wanted sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ== but got sha1-No8lEtefnUb9/HE0mueHi7weuVw=. (25587 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== integrity checksum failed when using sha512: wanted sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== but got sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=. (8851 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ== integrity checksum failed when using sha512: wanted sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ== but got sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=. (4142 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== integrity checksum failed when using sha512: wanted sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== but got sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=. (8851 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== integrity checksum failed when using sha512: wanted sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg== but got sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=. (8851 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-8T7Zn1AhMsQ/HI1SjcCfT/t4ii3eAqco3yOcSzS4mozsOz69lHLsoMXmF9nZgnFanYscnSlUSgs8uZyKzpE6kg== integrity checksum failed when using sha512: wanted sha512-8T7Zn1AhMsQ/HI1SjcCfT/t4ii3eAqco3yOcSzS4mozsOz69lHLsoMXmF9nZgnFanYscnSlUSgs8uZyKzpE6kg== but got sha1-3ACaJGuNCaF3tLegrne8Vw9LG3k=. (2516 bytes)
WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.

> [email protected] install /usr/local/projects/blockcahin/blockchain-cli/node_modules/fsevents
> node install

[fsevents] Success: "/usr/local/projects/blockcahin/blockchain-cli/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] install /usr/local/projects/blockcahin/blockchain-cli/node_modules/wrtc
> node-pre-gyp install --fallback-to-build

[wrtc] Success: "/usr/local/projects/blockcahin/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-darwin-x64/wrtc.node" is installed via remote
added 684 packages in 13.969s

Start script throws an error

When I run npm start, it gives me this error:

'.' is not recognized as an internal or external command, operable program or batch file.
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.10.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `./main.js`
npm ERR! Exit status 1

In order to fix the error, I changed the start script to node ./main.js.

Error on 'discover' command

I got this error on the peer I send the discover command. (Only him is affected)
I'm also doing this test only on localhost. All nodes are in the same computer, but in different ports.

node: symbol lookup error: /home/victor/.nvm/versions/node/v8.2.1/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-linux-x64/wrtc.node: undefined symbol: XOpenDisplay

I'll investigate it further, but any light is welcome. :)

PS: this bug was found on Linux.

not yet supported outside strict mode

Hi

$  npm install blockchain-cli -g
/Users/jorge/.nvm/versions/node/v4.8.0/bin/blockchain -> /Users/jorge/.nvm/versions/node/v4.8.0/lib/node_modules/blockchain-cli/main.js

> [email protected] install /Users/jorge/.nvm/versions/node/v4.8.0/lib/node_modules/blockchain-cli/node_modules/wrtc
> node-pre-gyp install --fallback-to-build

[wrtc] Success: "/Users/jorge/.nvm/versions/node/v4.8.0/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v46-darwin-x64/wrtc.node" is installed via remote
+ [email protected]
added 244 packages in 24.765s
Jorges-MBP:website jorge$ blockchain 
/Users/jorge/.nvm/versions/node/v4.8.0/lib/node_modules/blockchain-cli/lib/blockchain/index.js:7
class Blockchain {
^^^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/Users/jorge/.nvm/versions/node/v4.8.0/lib/node_modules/blockchain-cli/lib/cli/command/list-blockchain.js:1:82)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

Display entire hash

Hi there,

Thanks for building this CLI. It's a really cool way to play around with a blockchain in a really interactive way.

Is there a way to display the full hash and previous hash values? I think it would be helpful if one could take the previous block and manually calculate the next hash to get a deeper understanding of how the blocks are generated, unfortunately the hash is clipped in the table display like so:

┌─────────────────────────────────────────┐
│               ⛓  Block #1               │
├────────────────────┬────────────────────┤
│ ⏮  Previous Hash   │ 0000018035a828da0… │
├────────────────────┼────────────────────┤
│ 📅  Timestamp       │ Fri, 15 Sep 2017   │
│                    │ 16:04:40 GMT       │
├────────────────────┼────────────────────┤
│ 📄  Data            │ hello              │
├────────────────────┼────────────────────┤
│ 📛  Hash            │ 00002ddfc3a099f0b… │
├────────────────────┼────────────────────┤
│ 🔨  Nonce           │ 86328              │
└────────────────────┴────────────────────┘

Error when install dependencies

Hi guys,

After running sudo npm install, i was received some errors:

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ndc07/.npm/_logs/2018-12-12T17_33_36_212Z-debug.log

My configuration: Ubuntu 18.04, Node v10.14.2, npm v6.4.1

Thanks for helping me 🙏

Can't run blockchain command after installation

Error message is:

module.js:529
throw err;
^

Error: Cannot find module '/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/build/wrtc/v0.0.62/Release/node-v57-darwin-x64/wrtc.node'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/blockchain-cli/node_modules/wrtc/lib/peerconnection.js:6:15)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)

Any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.