This is a basic implementation of a blockchain in Go. It demonstrates core blockchain concepts like:
- Block structure
- SHA-256 hashing
- Proof-of-Work (mining)
- Block chaining via hashes
blockchain-go/
├── cmd/
│ └── blockchain/
│ └── main.go # CLI entrypoint
├── internal/
│ └── blockchain/
│ └── blockchain.go # Blockchain logic
├── go.mod
└── README.md
git clone https://github.com/yourusername/blockchain-go.git
cd blockchain-gogo run ./cmd/blockchainMining block 1...
Block mined! Hash: 000a1b4c...
Mining block 2...
Block mined! Hash: 000d9f2e...
Block #1:
Data: First block after Genesis
Hash: ...
PrevHash: ...
Block #2:
Data: Another block
Hash: ...
PrevHash: ...
In blockchain.go, you can change the mining difficulty by shortening or adding the target prefix.
For example, you can increase the difficulty by adding another zero in the prefix, "000"
const targetPrefix = "00" // Difficulty: hash must start with thisHere are a few ideas to expand this:
- 🧑💻 Create a web API to submit and view blocks (using
net/httporgin) - 💾 Save blockchain data to a file or database
- 📡 Connect multiple nodes with peer-to-peer networking
- 📉 Track and display mining stats or block explorer UI
This project is designed to help you learn:
- How blockchains work internally
- Hashing and nonce mechanisms
- Structs and methods in Go
- Command-line Go applications
MIT — feel free to use, copy, and modify.