https://github.com/kujenga/rockchain
A simple blockchain implementation in Rust
https://github.com/kujenga/rockchain
Last synced: 2 months ago
JSON representation
A simple blockchain implementation in Rust
- Host: GitHub
- URL: https://github.com/kujenga/rockchain
- Owner: kujenga
- License: mit
- Created: 2017-11-20T04:50:42.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T18:36:06.000Z (12 months ago)
- Last Synced: 2025-03-17T21:38:55.747Z (2 months ago)
- Language: Rust
- Homepage:
- Size: 131 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rockchain
[](https://github.com/kujenga/rockchain/actions)
[](https://ci.appveyor.com/project/kujenga/blockchain)A blockchain written in Rust.
This project is aimed at furthering my personal understanding of Rust. The
blockchain implementation is based on the following walkthrough, which was
originally done in Python:https://hackernoon.com/learn-blockchains-by-building-one-117428612f46
Many thanks to the original author!
## Usage
The following command will start the blockchain server.
```sh
RUST_LOG=blockchain,iron,logger=info cargo run
```View the blockchain in it's empty genesis state:
```sh
curl http://localhost:3000/chain | jq
```Create a new transaction:
```sh
curl -XPOST http://localhost:3000/transactions/new -H 'Content-Type: application/json' --data '{
"sender": "me",
"recipient": "you",
"amount": 123
}' | jq
```Trigger mining, creating a new block:
```sh
curl http://localhost:3000/mine | jq
```View the blockchain again, with the requested transaction now persisted within
a block:```sh
curl http://localhost:3000/chain | jq
```### Creating a network
The `PORT` environment variable can be used to set a custom port number. In
another window, another node can be started with the following command.```sh
RUST_LOG=blockchain,iron,logger=info PORT=3001 cargo run
```To manually register this node with the original one, the following request
can be performed:```sh
curl -XPOST http://localhost:3001/nodes/register -H 'Content-Type: application/json' --data '{
"nodes": [{
"address": "http://localhost:3000"
}]
}' | jq
```Trigger the execution of the consensus protocol, bringing state of the new
node up to date:```sh
curl http://localhost:3001/nodes/resolve | jq
```## Status
- [x] Building a blockchain
- [x] Blockchain API
- [x] Distributed Consensus
- [x] More idiomatic error handling
- [x] Refactor blockchain and server into separate modules
- [ ] Auto-register peers using CLI args
- [ ] Move blockchain data types into library crate