A simulated Blockchain written in Go. Followed this article for creating a single node, originally in python. Added some features to get it running as a network.
This is a brief overview on how to get it running, for more detail read this blog post.
-
First build the binary
cd go-blockchain && go build
-
Open two terminals and start two nodes:
./go-blockchain 8000
./go-blockchain 8001
-
Register the nodes with each other by hitting the
/nodes/register
endpoint:
curl --location --request POST \
'http://localhost:8000/nodes/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"nodes": [
"http://localhost:8001"
]
}'
- Add transactions to the network:
curl --location --request POST \
'http://localhost:8000/transactions/new' \
--header 'Content-Type: application/json' \
--data-raw '{
"sender":"sender1",
"recipient":"recipient2",
"amount": 12
}'
- View the current chain before we mine a block:
curl http://localhost:8000/chain
- Mine the block:
curl http://localhost:8000/mine
- Find the newly replaced chain on the second node:
curl http://localhost:8001/chain
- Create more transactions and mine more blocks.