/gochain-blkchain

A basic implementation of Blockchain

Primary LanguageGo

稍微复杂一些的,基本的概念实现都有,多了POW(工作量证明),交易添加等。

GoChain

A basic implementation of blockchain in go.

Building

$ cd cmd
$ go build -o gochain

Usage

Starting a node

You can start as many nodes as you want with the following command

./gochain -port=<port-number>

Endpoints

Requesting the Blockchain of a node

  • GET 127.0.0.1:8000/chain

Mining some coins

  • GET 127.0.0.1:8000/mine

Adding a new transaction

  • POST 127.0.0.1:8000/transactions/new

  • Body: A transaction to be added

    {
      "sender": "sender-address-te33412uywq89234g",
      "recipient": "recipient-address-j3h45jk23hjk543gf",
      "amount": 1000
    }

Register a new node in the network

Currently you must add each new node to each running node.

  • POST 127.0.0.1:8000/nodes/register

  • Body: A list of nodes to add

    {
       "nodes": ["http://127.0.0.1:8001", <more-nodes>]
    }

Resolving Blockchain differences in each node

  • GET 127.0.0.1:8000/nodes/resolve