A simple, persistent blockchain implementation with a CLI interface, written in Go.
Ferentum Blockchain is a minimal blockchain project designed for learning and experimentation. It includes:
- Blockchain core with blocks, hashing, and proof-of-work.
- CLI interface for adding blocks, printing the chain, and validation.
- Persistent storage using Go's
gobencoding.
- Create and manage a blockchain with a genesis block.
- Add new blocks with proof-of-work.
- Validate blockchain integrity.
- Persistent storage in
ferentum-blockchain.dat.
- Go (1.20 or later)
-
Clone the repository:
git clone https://github.com/ChristianPacifici/ferentum-blockchain.git cd ferentum-blockchain -
Build the CLI:
go build -o ferentum-blockchain ./cmd/cli
ferentum-blockchain/
├── go.mod
├── go.sum
├── main.go
├── blockchain/
│ ├── blockchain.go
│ └── pow.go
└── cmd/
└── cli/
└── cli.go
go build -o ferentum-blockchain ./cmd/cligo install tech.pacifici/blockchain/cmd/cli./ferentum-blockchain add "My Data"Adds a new block with the specified data to the blockchain.
./ferentum-blockchain printPrints all blocks in the blockchain, including their index, timestamp, data, previous hash, hash, and nonce.
Example Output:
Index: 0
Timestamp: [current time]
Data: Genesis Block
PrevHash:
Hash: [hash value]
Nonce: [nonce value]
---
Index: 1
Timestamp: [current time]
Data: First Block
PrevHash: [hash of genesis block]
Hash: [hash value]
Nonce: [nonce value]
---
./ferentum-blockchain validateValidates the integrity of the blockchain.
Example Output:
Is blockchain valid? true
./ferentum-blockchain resetResets the blockchain to the genesis block.
./ferentum-blockchain infoDisplays the number of blocks, the last block hash, and whether the blockchain is valid.
Example Output:
Number of blocks: 3
Last block hash: [hash value]
Is valid: true
./ferentum-blockchain mine "My Data"Mines a new block with the specified data and adds it to the blockchain.
Example Output:
Mined block #3 with hash: [hash value]
-
Reset the Blockchain
./ferentum-blockchain reset
-
Add Blocks
./ferentum-blockchain add "First Block" ./ferentum-blockchain add "Second Block"
-
Show Info
./ferentum-blockchain info
-
Mine a Block
./ferentum-blockchain mine "Mined Block" -
Print the Blockchain
./ferentum-blockchain print
-
Validate the Blockchain
./ferentum-blockchain validate
- Improve Error Handling: Add user-friendly error messages.
- Add Networking: Implement peer-to-peer communication.
- Add Transactions: Extend the blockchain to support transactions.
- Build some APIS: Add some go APIs.
Contributions are welcome! Open an issue or submit a pull request.
This project is open-source and available under the MIT License.
