A basic blockchain implementation written in Go

Blockchain

Having fun implementing a blockchain using Golang.

Using Minimum Viable Blockchain

Keys

The Blockchain uses ECDSA (224 bits) keys. When a user first joins the blockchain a random key will be generated.

Keys are encoded using base58.

Given x, y as the components of the public key, the key is generated as following:

	base58(BigInt(append(x as bytes, y as bytes)))

Proof of work

In order to sign a transaction and send it to the network, proof of work is required.

Proof of work is also required for block generation.

Protocol

The blockchain runs on port 9191 and uses TCP to handle connections among peers.

Message
  • Message type (1 byte)
     const (
     	MESSAGE_GET_NODES = iota + 20
     	MESSAGE_SEND_NODES
    
     	MESSAGE_GET_TRANSACTION
     	MESSAGE_SEND_TRANSACTION
    
     	MESSAGE_GET_BLOCK
     	MESSAGE_SEND_BLOCK
     )
    
  • Options (4 bytes): Data specific
  • Data (n bytes): Data specific
Transaction
  • Header:

    • From (80 bytes): Origin public key
    • To (80 bytes): Destination public key
    • Timestamp (4 bytes): int32 UNIX timestamp
    • Payload Hash (32 bytes): sha256(payloadData)
    • Payload Length (4 bytes): len(payloadData)
    • Nonce (4 bytes): Proof of work
  • Signature (80 bytes): signed(sha256(header))

  • Payload data (Payload Length bytes): raw data

Block
  • Header:

    • Origin (80 bytes): Origin public key
    • Timestamp (4 bytes): int32 UNIX timestamp
    • Previous block (32 bytes): sha256(previous block header)
    • Merkel Root (32 Bytes): sha256(transaction hashes)
    • Nonce (4 bytes): int32 UNIX timestamp
  • Signature (80 bytes): signed(sha256(header))

  • Block transactions

Owner
Jorge Izquierdo
Cofounder @aragon, @aragonone
Jorge Izquierdo
Similar Resources

goBlockChain is a version of the classic blockChain with POW algorithms written in golang.

goBlockChain is a version of the classic blockChain with POW algorithms written in golang. May come in handy when learning about this technology.

Oct 31, 2021

DERO Homomorphic Encryption Blockchain Protocol

DERO Homomorphic Encryption Blockchain Protocol

Homomorphic encryption is a form of encryption allowing one to perform calculations on encrypted data without decrypting it first. The result of the computation is in an encrypted form, when decrypted the output is the same as if the operations had been performed on the unencrypted data.

Dec 27, 2022

DERO: Secure, Anonymous Blockchain with Smart Contracts. Subscribe to Dero announcements by sending mail to [email protected] with subject: subscribe announcements

DERO: Secure, Anonymous Blockchain with Smart Contracts.  Subscribe to Dero announcements by sending mail to lists@dero.io with subject: subscribe announcements

Welcome to the Dero Project DERO News Forum Wiki Explorer Source Twitter Discord Github Stats WebWallet Medium Table of Contents ABOUT DERO PROJECT DE

Dec 7, 2022

run ABI encoded data against the ethereum blockchain

Run EVM code against a database at a certain block height - Note You can't run this against a running geth node - because that would share the db and

Nov 11, 2021

Go module for the Cardano Blockchain

cardano-go cardano-go is both a library for creating go applicactions that interact with the Cardano Blockchain as well as a CLI to manage Cardano Wal

Dec 1, 2022

chia-blockchain some function implement in golang

gochia chia-blockchain some function implement in golang Package bls-signatures implement blspy Usage? Now we can use it to generate plot memo and id,

May 27, 2022

Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint.

Frontier Chain Frontier Chain is a blockchain application built using Cosmos SDK and Tendermint. Setup Initialize the blockchain with one validator no

Jul 12, 2022

Implementing blockchain using Golang ✔️

 Implementing blockchain using Golang ✔️

Implementing blockchain using Golang ✔️ Keys The Blockchain uses ECDSA (224 bits) keys.

May 24, 2022

LINE Financial Blockchain forked from gaia

LFB(LINE Financial Blockchain) This repository hosts LFB(LINE Financial Blockchain). This repository is forked from gaia at 2021-03-15. LFB is a mainn

Dec 21, 2022
Comments
  • Nodes can not connect

    Nodes can not connect

    When I run docker.sh,I found that any nodes can not connect.And I can not do anything after that because it stay here. image

    Do you have the same problem?And how you solve it ?

  • /core/main.go:17: undefined: OpenConfiguration

    /core/main.go:17: undefined: OpenConfiguration

    src/core/main.go:17: undefined: OpenConfiguration src/core/main.go:17: undefined: HOME_DIRECTORY_CONFIG src/core/main.go:22: undefined: WriteConfiguration src/core/main.go:22: undefined: HOME_DIRECTORY_CONFIG

  • Transaction - Proof-of-Work not required.

    Transaction - Proof-of-Work not required.

    Based on Satoshi's paper here - https://bitcoin.org/bitcoin.pdf though blocks have proof-of-work transactions do not. The code here checks the POW on the transactions as well - https://github.com/izqui/blockchain/blob/master/core/transaction.go#L58

    Am I missing something here? Please let me know. Thank you in advance.

  • undefined issue

    undefined issue

    Hi,what other lib should I import to resolve following issue? ../../go/src/github.com/izqui/blockchain/core/main.go:17: undefined: OpenConfiguration ../../go/src/github.com/izqui/blockchain/core/main.go:17: undefined: HOME_DIRECTORY_CONFIG ../../go/src/github.com/izqui/blockchain/core/main.go:22: undefined: WriteConfiguration ../../go/src/github.com/izqui/blockchain/core/main.go:22: undefined: HOME_DIRECTORY_CONFIG

A basic implementation of Blockchain

GoChain A basic implementation of blockchain in go. Building $ cd cmd $ go build -o gochain Usage Starting a node You can start as many nodes as you

Nov 26, 2022
Blockchain-go - A repository that houses a blockchain implemented in Go

blockchain-go This is a repository that houses a blockchain implemented in Go. F

May 1, 2022
Use golang to reproduce the basic blockchain

Blockchain_with_Go Use golang to reproduce the basic blockchain Update Panel V0.1 No transactions but noly blocks are allowed. V0.5 Transactions are n

Dec 30, 2022
A simplified blockchain implementation in Golang

A simplified blockchain implementation in Golang

Dec 31, 2022
Implementation of blockchain using golang

go-blockchain Basic implementation of blockchain using golang. Initialize Blockc

Feb 18, 2022
Mini Blockchain Implementation In Golang Inspired by Go-Ethereum🚀

JP Blockchain ?? ?? Mini Blockchain Implementation In Golang Inspired by Go Ethereum & BlockChain Bar by Lukas (Web3Coach) Features Working Core Compo

Aug 8, 2022
Blockchain implementation with Go

Ultra Basic Blockchain with Go Ultra-basic blockchain implementation with Go. Ru

Feb 17, 2022
Kava - Reference implementation of Kava, a blockchain for cross-chain DeFi. Built using the cosmos-sdk

DeFi for Crypto. Telegram | Medium | Discord Reference implementation of Kava, a

Apr 4, 2022
Gochain is a Blockchain written in go
Gochain is a Blockchain written in go

gochain gochain is a proof-of-work blockchain written in go. Features Proof-Of-Work Persistence CLI Transactions Addresses Merkle Tree Network How to

Jul 14, 2022
Stackledger: a new blockchain written in golang

StackLedger Stackledger is a new blockchain. It is written in golang and uses a novel networking stack built from two primitives: channels and extensi

Feb 21, 2022