Skip to content

greenteabiscuit/go-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-blockchain

This repository is based on the article Learn Blockchains by Building One. I basically used golang to reimplement the contents of the article.

You can create a multi-node blockchain using the code and can understand

  • how transactions are added to the block
  • how blocks are added to the chain
  • how nodes communicate with each other to resolve conflict and reach consensus

Basics

To run multiple nodes:

go run main.go :8080
go run main.go :8081

List of APIs:

$ curl localhost:8080/chain
$ curl localhost:8080/mine
$ curl localhost:8080/transactions/new -d \
'{"sender":"exampleSender", "recipient": "exampleRecipient", "amount":1}'
$ curl localhost:8080/nodes/register -d \
'{"Nodes": "localhost:8081"}'
$ curl localhost:8080/nodes/resolve

Simulating the code

Run multiple nodes

$ go run main.go :8080
$ go run main.go :8081

Register the node

$ curl localhost:8080/nodes/register -d \
'{"Nodes": "localhost:8081"}'

Mine on the second node

$ curl localhost:8081/mine

The second chain should be longer than the first chain now. Resolve the conflict.

$ curl localhost:8080/nodes/resolve

About

Multi-node blockchain implemented in go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages