Giter VIP home page Giter VIP logo

blockchain's Introduction

Node.js Blockchain demo

Based on Eric Traub tutorial

API endpoints

  • api/blockchain : get, gets the blockchain
  • api/transaction/broadcast: post, posts a transaction to be broadcasted. Returns status code 200 if successful
  • api/transaction:
    • post . Posts transaction to be added to the pending transactions.
    • get ?id = . Gets transaction details
  • api/register_and_broadcast_node : post, Posts the new node to be added and broadcasred
  • api/register_node: post, Registers new node
  • api/register_bulk: post, Registers new node
  • api/mine: get, Mine a new, include the pending transactions in it.
  • api/receive_new_block: post, Register new block in the chain.
  • api/consensus: get, Gets the chain consensus. Node chain is updated if different than consensus.
  • api/block: get ?hash = . Gets block details
  • api/address: get ?address = . Gets transactions and balance for the specified address.

const router = { '' : handlers.index, 'api/block' : handlers.block, 'api/consensus' : handlers.consensus, 'api/address' : handlers.address, 'api/transaction' : handlers.transaction, 'api/transaction/broadcast' : handlers.transaction_broadcast, 'api/register_bulk' : handlers.register_bulk, 'api/register_node' : handlers.register_node, 'api/register_and_broadcast_node' : handlers.register_and_broadcast_node, 'api/receive_new_block' : handlers.receive_new_block, 'api/mine' : handlers.mine, 'api/blockchain' : handlers.blockchain, 'ping' : handlers.ping, 'notFound' : handlers.notFound, 'favicon.ico' : handlers.favicon, 'public' : handlers.public }

HTML

index.html demonstrates search (Block, Transaction, Address).

Example use

  • Start 5 network nodes, listening on ports 3001 to 3005
    • npm run node_1
    • npm run node_2
    • npm run node_3
    • npm run node_4
    • npm run node_5
  • Postman, register network nodes
    • localhost:3001/api/register_and_broadcast_node , payload {"newNode":"localhost:3002"}
    • localhost:3001/api/register_and_broadcast_node , payload {"newNode":"localhost:3003"}
    • localhost:3001/api/register_and_broadcast_node , payload {"newNode":"localhost:3004"}
    • localhost:3001/api/register_and_broadcast_node , payload {"newNode":"localhost:3005"}
  • Postman, Broadcast transactions e.g.
    • localhost:3001/api/register_and_broadcast_node, payload {"amount": 100, "sender":"me", "recipient":"mkjhe"}
  • Postman, mine new block
    • localhost:3001/api/mine
  • Browser localhost:3002 and play
  • Stop and restart a node e.g. node_5. Then get consensus from that node
    • localhost:3005/api/cosensus

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.