[
onechain
Assist in developing blockchain core efficiently.
2018 OSS Grand Developers Challenge Award
2019 OSS Grand Developers Challenge Award
Inspired by lhartikk/naivechain.
Live Demo
Run onechain on Ainize! You can access the live onechain with the endpoint provided by Ainize, a serverless platform for open-source projects.
For example, you can see all blocks in blockchain with a /blocks
GET request (i.e. HERE) .
onechain-explorer
Click on the above image to go to the
onechain-explorer
repo.
A onechain explorer
is the front-end used to visualize the state of the blockchain. This blockchain explorer allows users to see the latest blocks and details about a particular block. onechain already has multiple functions with HTTP (RESTful API) endpoints. So the web page calls those endpoints and visualizes the results.
The full UI code is located in lukepark327/onechain-explorer repo. Vue.js and Vuetify are used.
Abstract
As Blockchain-based services grew, so open-source that assists in developing blockchain core was needed. There are open-source projects like Bitcoin and Ethereum, but those are too hard to learn and to use.
We solve the above problems with a
onechain
, simple implementation of blockchain core.
The onechain adopts modular design: Dividing layers into blockchain, network, APIs, and wallet for clarity. Also, detailed comments and documents are provided to facilitate learning and reusing. Both front-end and back-end of onechain is written in Javascript (Node.js and Vue.js) but written in simple (without async, et al.) so that other language developers can understand them.
Use-cases
📖 컴퓨터과학으로 배우는 블록체인 원리와 구현
Click on the above image to go to the bookstore.
Governance Simulator on Blockchain : Based on Smart City Cases
Blockchain Policy Simulator
edu-chain
Plasma DAG
Docker Quick Start
docker run -it -p 3001:3001 -p 6001:6001 lukepark327/onechain
How to Start
Environments
- Node.js v8.11.3
- cURL 7.55.1 or Postman v6.4.4
Install dependencies
npm install
Run Nodes
Start node #1
npm start
Start node #2
-
Set
HTTP_PORT
for HTTP communication$env:HTTP_PORT=3002
orexport HTTP_PORT=3002
-
Set
P2P_PORT
for P2P communication among peers$env:P2P_PORT=6002
orexport P2P_PORT=6002
-
(option) Set pre-connected
PEERS
before running$env:PEERS="ws://127.0.0.1:6001[, ws://127.0.0.1:6003, ...]"
orexport PEERS="ws://127.0.0.1:6001[, ws://127.0.0.1:6003, ...]"
-
(option) Set
PRIVATE_KEY
where private_key is located$env:PRIVATE_KEY="second"
orexport PRIVATE_KEY="second"
Now private_key is located in
./wallet/second/
instead of default location./wallet/default/
.
npm start
How to Use
Click on the above image to play the video.
Get blockchain
curl http://127.0.0.1:3001/blocks
Use 'pretty-print JSON' for better readability:
curl http://127.0.0.1:3001/blocks | python -m json.tool
Python >= 2.6 is required.
Get a particular block
curl http://127.0.0.1:3001/block/:number
For example, let us get a block whose number (index) is 3:
curl http://127.0.0.1:3001/block/3
Add new block
curl -X POST http://127.0.0.1:3001/mineBlock
curl -H "Content-type:application/json" --data "{\"data\" : [\"Anything you want\", \"Anything you need\"]}" http://127.0.0.1:3001/mineBlock
Get current version
curl http://127.0.0.1:3001/version
Get the version of particular block
curl http://127.0.0.1:3001/blockVersion/:number
For example, let's get a version of a block whose number (index) is 3:
curl http://127.0.0.1:3001/blockVersion/3
Get connected peer(s)
curl http://127.0.0.1:3001/peers
Add peer(s)
curl -H "Content-type:application/json" --data "{\"peers\" : [\"ws://127.0.0.1:6002\", \"ws://127.0.0.1:6003\"]}" http://127.0.0.1:3001/addPeers
Get Address
curl http://127.0.0.1:3001/address
Stop
curl -X POST http://127.0.0.1:3001/stop
License
The onechain project is licensed under the Apache License, Version 2.0, also included in our repository in the LICENSE file.