This project is a simple implementation of a blockchain in C++. It demonstrates the basic concepts of a blockchain, including blocks, transactions, and the cryptographic hashing mechanism that ensures the integrity and immutability of the blockchain.
A blockchain is a decentralized and immutable digital ledger that records transactions across multiple computers. It ensures transparency, security, and trust in financial transactions by linking blocks of data together in a sequential and cryptographically secure manner.
- Create a new blockchain
- Add blocks with transactions to the blockchain
- Print the entire blockchain
- Validate the integrity of the blockchain
- C++ compiler (e.g., GCC, Clang, or MSVC)
- Download and install MinGW from the official website: MinGW.
- After installation, add the MinGW
bin
directory to your system'sPATH
environment variable.
macOS comes with a pre-installed GCC compiler. However, you can also install the latest version of GCC or Clang from Homebrew:
-
Install Homebrew by following the instructions on the official website.
-
Once Homebrew is installed, run the following command to install GCC:
brew install gcc
Or, install Clang with:
brew install llvm
Most Linux distributions come with GCC pre-installed. If not, you can install it using your distribution's package manager. read more.
-
On Debian-based distributions (e.g., Ubuntu):
sudo apt-get install build-essential
-
Clone the repository:
git clone https://github.com/ajaykumargdr/basic-blockchain.git
-
Navigate to the blockchain folder:
cd basic-blockchain/blockchain
-
Compile the source code using the appropriate compiler command for your operating system:
-
On Windows (MinGW):
g++ -std=c++11 -o main main.cpp block.cpp blockchain.cpp transaction.cpp
-
On macOS or Linux (GCC):
g++ -std=c++11 -o main main.cpp block.cpp blockchain.cpp transaction.cpp
-
On macOS or Linux (Clang):
clang++ -std=c++11 -o main main.cpp block.cpp blockchain.cpp transaction.cpp
-
-
Run the compiled executable:
./main
This will create a new blockchain, add some sample blocks with transactions, print the entire blockchain, and validate its integrity.
Contributions to this project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.