A foundational blockchain implementation in Go focusing on core concepts and principles. This educational project is actively being developed to demonstrate and explore blockchain technology through hands-on code.
- Basic blockchain structure with proof-of-work mining
- SHA-256 hash generation and chain validation
- Configurable mining difficulty (leading zeros)
- Block generation time tracking
- Genesis block creation
- Transactions and wallet implementation
- Merkle trees for efficient verification
- Distributed network capabilities
- P2P networking
- Consensus mechanisms
- Smart contracts
- Block persistence (database integration)
- Web interface for blockchain exploration
- Clone the repository
git clone https://github.com/yourusername/go-blockchain.git
cd go-blockchain
- Ensure Go is installed (version 1.16 or higher)
go version
- Run the program
go run main.go
The program prompts for the number of leading zeros required for the proof-of-work:
Enter how many zeros the hash must start with:
> 4
Example output:
Genesis Block:
Id: 1
Timestamp: 1683924000000000000
Magic Number: 123456
Hash of the previous block:
0
Hash of the block:
0000a1b2c3d4e5f6...
Block was generating for 2 seconds
Block:
Id: 2
...
- User specifies required number of leading zeros
- Program generates random magic numbers
- Each magic number is used to create a potential block hash
- When a hash with the required zeros is found, the block is created
- Block is linked to previous block via hash chain
- Generation time is recorded
- Each block contains the previous block's hash
- Hash must start with specified number of zeros
- Genesis block has a previous hash of "0"
type Block struct {
Id int
Magic_number int32
Time_stamp int64
PrevHash string
Hash string
Gen_time time.Duration
}
// Creates the genesis block
func CreateGenesisBlock(numZeros int) Block
// Creates a new block linked to the previous one
func CreateNewBlock(prevBlock Block, id int, numZeros int) Block
// Generates SHA-256 hash
func GeneratHash(id int, timestamp int64, magicNumber int32, preHash string, numZeros int) string
// Validates hash meets difficulty requirement
func validateHash(hash string, numZeros int) bool
This project is designed to help understand:
- Blockchain fundamentals
- Proof-of-work concepts
- Cryptographic hashing
- Chain validation
- Block generation and mining
- Timestamp and duration tracking
This is a work in progress, and contributions are welcome! Areas you can help with:
- Implementing planned features
- Improving documentation
- Adding tests
- Code optimization
- Bug fixes
To contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This is an educational project designed for learning blockchain concepts. It's actively being developed and improved. Not intended for production use.
This project is licensed under the MIT License - see the LICENSE file for details.
Your Name - @AviTheBrown
Project Link: https://github.com/AviTheBrown/GoBlockchain
Feel free to contribute, suggest features, or use for educational purposes! Star β the repository if you find it helpful!