https://github.com/streamdp/goblockchain
goBlockChain is a version of the classic blockChain with POW algorithms written in golang. May come in handy when learning about this technology.
https://github.com/streamdp/goblockchain
blockchain-demos gin-gonic gitflow-workflow sha1
Last synced: about 1 month ago
JSON representation
goBlockChain is a version of the classic blockChain with POW algorithms written in golang. May come in handy when learning about this technology.
- Host: GitHub
- URL: https://github.com/streamdp/goblockchain
- Owner: streamdp
- License: apache-2.0
- Created: 2021-10-30T18:34:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-30T20:59:00.000Z (over 3 years ago)
- Last Synced: 2024-12-06T07:42:20.707Z (5 months ago)
- Topics: blockchain-demos, gin-gonic, gitflow-workflow, sha1
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goblockchain
This repo contains a simple/basic blockchain realisation in Go, with a basic code organization.
We use:
* gin-gonic/gin package to start and serve HTTP server
* crypto/sha1 to get SHA1 hashesgoblockchain use [Taskfile](https://dev.to/stack-labs/introduction-to-taskfile-a-makefile-alternative-h92) (a Makefile alternative).
Please read the [Building Blockchain from Scratch in Python](https://python-scripts.com/blockchain) article in order to know more about this repository.
## Build the app
```bash
$ go build -o bin/goBlockChain internal/main.go
````
or
```bash
$ task build
````
## Run the app
```bash
$ ./bin/goBlockChain
```
or
```bash
$ task run
```
The default port is 8080, you can test the application in a browser or with curl:
```bash
$ curl 127.0.0.1:8080/chain
```
You can choose a different port and run more than one copy of goBlockChain on your local host. For example:
```bash
$ ./bin/goBlockChain -port 8081
```
List of the endpoints:
* GET **/ping** _check node status_
* GET **/mine** _mine a new block_
* GET **/chain** _get the current state of the blockchain on a node_
* GET **/nodes/resolve** _get actual copy of the blockchain_
* GET **/mine/complexity/increase** _increase the difficulty of mining blocks_
* GET **/mine/complexity/decrease** _decrease the difficulty of mining blocks_
* POST **/transactions/new** _make a new transaction_
* POST **/nodes/register** _add a new node to the list of nodes_Example of sending a POST request to add a new transaction to the blockchain:
```bash
$ curl -X POST -H "Content-Type: application/json" -d '{ "sender": "1914116639ac11ec83092c6fc90649b9", "recipient": "7e93670390396556d432206c1c3231fbb", "amount": 10}' "http://localhost:8080/transactions/new"
```