blockchain-in-golang-using-docker

command module
v0.0.0-...-00ad908 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2022 License: MIT Imports: 13 Imported by: 0

README

Blockchain in Golang using Docker

The link to the medium article explaining the code is here

Installation and Usage

Dependencies

Install Go

Install Docker

Set up the server and run the blockchain

Run the following commands in a new terminal. Clone this repository:

$ git clone https://github.com/divija-swetha/Blockchain-in-Golang-using-Docker.git
$ cd Blockchain-in-Golang-using-Docker
$ go run Blockchain-in-Golang-using-Docker.go
Server listening on localhost:5000.

Blockchain

Running the blockchain on the server

$ curl localhost:5000/chain
Mining Blocks

To see the mining process on the selectedserver address, run the following command

$ curl localhost:5000/mine
Adding a New Transaction

To add a new transaction on blockchain, we need the block content i.e., the sender address, the receiver address and the amount sent from sender to the receiver. A new transaction can be added in a block mined by a miner at a perticular server address.

$ curl -X POST -H "Content-Type: application/json" -d '{
"sender": "66ad49fc75114203-8db2c886c13339ea",
"recipient": "98c438146f674768a1bb0e225a75311f",
"amount": 50
}' localhost:5000/transactions/new
Adding a new node into the network

The new server addresses need to be registered to the previous address to form a network.

$ curl -X POST -H "Content-Type: application/json" -d '{
"nodes": ["http://localhost:5001","http://localhost:5002"]
}' localhost:5000/nodes/register
Resolve nodes

If there are more than one nodes, then, run the following command to resolve nodes.

$ curl localhost:5000/nodes/resolve 

Adding more instances

We can add more instances to the blockchain network using the following commands.

$ go run blockchain.go -p 5001
$ go run blockchain.go -p 5002
$ go run blockchain.go -p 5003

Docker

The code can be executed using Docker using the following commands.

$ docker build -t blockchain .
$ docker run --rm -p 9000:5000 blockchain
$ docker run --rm -p 9001:5000 blockchain
$ docker run --rm -p 9002:5000 blockchain

License

MIT LICENSE

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL