Skip to content

luisedmc/BlockchainGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlockchainGo

BlockchainGo is a simple implementation of the Blockchain technology in Go language. This project was build to learn more about the Blockchain technology and its features. The code was written with some comments in a way that can maybe help understand the most complicated parts. The code is also very direct, I didn't try to reinvent the wheel, just implement some of the Blockchain features.

I will be adding more features to this project in the future. See Roadmap section for more details.

Disclaimer

Like i said before, this project was built for learning purposes. It is not a production ready code. It is not secure or optimized and probably was not written in the best way.

Table of Contents

Blockchain

What's Blockchain?

Rick and Morty explaning Blockchain

Blockchain technology is a secure database that allows transparent information sharing inside a network. This database is public, so everyone can visualize the records inside but can't delete or modify the data (something like a read-only database). All the data are stored in an immutable encrypted container that anyone can track called block.

Blocks

Blocks are used to store the data inside the Blockchain. Each block has a unique identifier called hash. This hash is generated by the hash of the previous block. This way, all the blocks are connected, like a chain, and it is impossible to change the data inside a block without changing the hash of the block and all the following blocks. That's why this tecnology is called Blockchain.

Transactions

As I said before, the Blockchain stored encrypted data in blocks, which are a very safe way to store data. This works very well in the context of transactions. For example, if you want to sell some cryptocurrencies for your friend, the Blockchain will create a unique ledger for the seller and buyer.

The transactions inside the Blockchain connect people with people without relying on any financial system (peer-to-peer), making this whole process a lot safer.

Wallet

Wallet is simply the local you store your and manage your cryptocurrencies. It consists of two parts: a Public Address and a Private Key. The Public Address is the Wallet Address and is a string of characters that other people can use to send you cryptocurrency. The Private Key is a secret string of characters that you use to access your wallet (very important to keep this one in a safe place).

Current State

At the current state, the BlockchainGo has the following features:

  • Create a new Blockchain and store it in the database
  • Print the All Blocks
  • Transactions
  • Get the balance of a specific address
  • Create a valid BTC Wallet address

Usage

Clone this repository and change to the project directory:

git clone https://github.com/luisedmc/BlockchainGo && cd BlockchainGo

If some packages are missing, you can get them with go mod tidy

In the project directory, just go run main.go or go run . and then the commands listed below.

You can also build the binary file with go build and then run it using ./BlockchainGo

Commands

Command Description
createBlockchain -address ADDRESS Create a new Blockchain with the given address as the first miner
printChain Print all the blocks of the blockchain
getBalance -address ADDRESS Get the balance of the given address
send -from FROM -to TO -amount AMOUNT Send the given amount of coins from one address to another
createWallet Create a new BTC wallet address

Example

go run . createBlockchain -address "luisedmc" or ./BlockchainGo createBlockchain -address "luisedmc"

Roadmap

Features that I would like to implement in the future:

  • Wallets
  • Signatures
  • Web Server
  • Ethereum

Releases

No releases published

Packages

No packages published

Languages