Giter Club home page Giter Club logo

blockchain's Introduction

Blockchain

Build Status

A "naive blockchain" implementation in Elixir inspired by this JS implementation This is an umbrella project that provides the blockchain core and a REST API built with Phoenix. It provides peer-to-peer communications, naive blockchain logic and a rudimentary Proof of Work.

Usage

Setting up a 3 nodes blockchain locally:

  • node 1: iex -S mix phx.server (defaults: PORT=4000 P2P_PORT=5000)
  • node 2: PORT=4001 P2P_PORT=5001 iex -S mix phx.server
  • node 3: PORT=4002 P2P_PORT=5002 iex -S mix phx.server

Then connect the nodes using the REST API, for example:

curl -H 'Content-Type: application/json' localhost:4001/api/peers -X POST -d '{ "uri": "localhost:5000"}'  # connect node2 to node1

curl -H 'Content-Type: application/json' localhost:4002/api/peers -X POST -d '{ "uri": "localhost:5001"}'  # connect node3 to node2

or directly in the iex console:

$node2> Blockchain.connect("localhost:5000") # connect node2 to node1

$node3> Blockchain.connect("localhost:5001") # connect node3 to node2

You can then mine blocks using the REST API or directly in the iex console.

iex

Interaction with the blockchain in the iex console:

Blockchain.connect("host:port") # connect to a peer
Blockchain.list_peers() # list direct peers
Blockchain.mine("some data") # add a block to the blockchain
Blockchain.blocks() # get all blocks in the chain

REST API

Interaction with the blockchain with the REST API:

# create a block
curl -H 'Content-Type: application/json' localhost:4000/api/blocks -X POST -d '{"data": "block data"}'

# show the blockchain
curl -H 'Content-Type: application/json' localhost:4000/api/blocks

# show connected peers
curl -H 'Content-Type: application/json' localhost:4000/api/peers

# connect to a peer
curl -H 'Content-Type: application/json' localhost:4002/api/peers -X POST -d '{ "uri": "localhost:5001"}'

Motivations / next steps

The goal of this project is to understand basic mechanisms behind the blockchain and to use Elixir and OTP. It has been designed to be modular and extensible. Some ideas to make it more complete :

  • web UI to control the node
  • build more blockchain features to make it a less "naive" blockchain

Issues and pull requests are very welcome ๐Ÿ˜Š

Resources

For future improvements:

blockchain's People

Contributors

robinmonjo avatar

Watchers

 avatar

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.