A command-line interface for a simple blockchain module in Go.
A commandline interface for a simple blockchain module in Go. This project is an academic pursuit of mine to learn more about blockchain and implement one on myself. The charts
folder has some great diagrams that can be used to understand certain concepts of blockchain.
This module uses SHA256 hashing and so obviously should not be used for sensitive data (SHA256 can be cracked with relative ease). The module uses BadgerDB to store the blockchain and ensure persistance.
As of now, 1 block can only have 1 transaction because the mining of the block is synchronous with the sending of a transaction. Each block has an input and an output. The input stores an unhashed public key and a signature of the entire transaction and the output stores a hashed public key. So to access the unspent tokens in the output, the hash of the public key in the input has to match the hashed public key in the output. You can see the flowchart of an example transaction here
There is a simple commandline application showing the module can be used. You can run it using go run main.go (flags)
. See Usage to learn about the flags.
printchain
Prints all the blocks in the chaingetbalance -address ADDRESS
gets the balance for a given addresscreateblockchain -address ADDRESS
creates a blockchainsend -from FROM -to TO -amount -AMOUNT
makes a transactioncreatewallet
- Creates a new Walletlistaddresses
- Lists the addresses in our wallet file
I am assuming you have go properly installed on your machine.
Mining the genesis block (Output is -1 for for the coinbase transaction)
First, we created the blockchain by proving the genesis block and subsequently having a coinbase transaction mining it. After this step, the balance at address "Pranav" is 100 (value of the coinbase transaction). Then we make a transaction from address "Pranav" to address "Manya". This first created an address "Manya" and then completed the transaction. We can see that it was succesful and that the blockchain is still valid after it.
If you find any issues, typos, errors or have any feature requests, feel free to create an issue or a pull request :)
- Persistance
- Transactions
- Consensus Algorithm
- Wallet Module
- Integrate wallet Module and the blockchain
- Digital Signatures
- Merkle Tree
- Dynamic Difficulty
- Improve the CLI Package