Skip to content

jseanchuang/simple_node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In Memory Blockchain

It's a single node blockchain demonstration. Without network or p2p connections, also no signature or verification. All blockchain data store in memory. The consensus would be straightforward: just collect transactions and make them blocks.

SPECIFICATION

  • It is an account based blockchain.
  • Newly observed accounts have 100 units of initial coins.
  • The blockchain generates a new block every 10 seconds.
  • Block header has the following message
    • Block hash: SHA256 hash of block.
    • Parent hash: Previous block hash.
    • Block height.
    • Transactions: Array of transaction hashes belong to this block.
  • Transaction has the following message:
    • Transaction hash: SHA256 hash of transaction.
    • From: from address.
    • To: to address.
    • Value: coins to transaction.
  • REST API to input transaction and further interaction
  • Dump blockchain log on console.

How to run

  1. Install npm packages
npm install
  1. Start node
npm start

Node interaction

After node start. Use curl command to interact with.

Transaction

  1. Create transaction. A POST requst with from, to and value parameters in request body. Response contains the same input data with additional txhash.
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"from":"acc1", "to":"acc2","value":3}' \
  http://localhost:3000/transaction
  1. Get transaction by txhash. A GET request with hash parameter.
curl -X GET "localhost:3000/transaction/0x4f7d1b75053426c78e6a51a0ebae18f805d61e67be6699df36ed77afeb13e8f6"

Address

  1. Get address info. A GET request with address parameter.
curl -X GET localhost:3000/address/acc1

Block

  1. Get current blockchain height. A GET request.
curl -X GET localhost:3000/block
  1. Get block info by height. A GET request with height parameter.
curl -X GET localhost:3000/block/height/2
  1. Get block info by block hash. A GET request with hash parameter.
curl -X GET localhost:3000/block/hash/0xb49437410bd457d6b680b0cb8f609163f00429200e614e12a6e0d9b6dbbb1f0c

About

Assignment for blockchain engineer interview

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published