A basic implementation of Blockchain

Overview

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 want with the following command

./gochain -port=<port-number>

Endpoints

Requesting the Blockchain of a node

  • GET 127.0.0.1:8000/chain

Mining some coins

  • GET 127.0.0.1:8000/mine

Adding a new transaction

  • POST 127.0.0.1:8000/transactions/new

  • Body: A transaction to be added

    {
      "sender": "sender-address-te33412uywq89234g",
      "recipient": "recipient-address-j3h45jk23hjk543gf",
      "amount": 1000
    }

Register a new node in the network

Currently you must add each new node to each running node.

  • POST 127.0.0.1:8000/nodes/register

  • Body: A list of nodes to add

    {
       "nodes": ["http://127.0.0.1:8001", <more-nodes>]
    }

Resolving Blockchain differences in each node

  • GET 127.0.0.1:8000/nodes/resolve
Comments
  • Package issue?

    Package issue?

    Hi Cristian, I get the following error when I build. Thank you for clue.

    gochain/cmd(master*) » go build -o gobuild
    main.go:6:5: cannot find package "github.com/crisadamo/gochain" in any of: /usr/local/Cellar/go/1.8.1/libexec/src/github.com/crisadamo/gochain (from $GOROOT) /Users/eos/go/src/github.com/crisadamo/gochain (from $GOPATH)

    opened by agentbond007 4
  • Hashing of blocks is not working

    Hashing of blocks is not working

    Hi,

    Nice project. Was working on a Go Blockchain implementation myself and noticed that your hashing always returns the same hash, throughout the entire chain.

    The thing is that you are trying to hash a block with binary.Write(&buf, binary.BigEndian, block) which gives you an error you don't handle. The data for binary.Write must be a fixed-size value, your Block contains a string which isn't fixed size.

    I've made a workaround by marshalling the block first, that way the binary.Write succeeds and your hashing the chain properly. It is a bit slow though, if you'll find a better solution, drop me a line.

    You can see it here, feel free to use it: https://github.com/Grrrben/gocoin/blob/master/blockchain.go#L55

    Cheers.

    opened by Grrrben 3
  • corrects readme and fixes headers not being written correctly

    corrects readme and fixes headers not being written correctly

    The command to run the script with a non-default port needed to be ./gochain -port=5000 instead of ./gochain 5000.

    Also, in order for the HTTP response to be encoded correctly, in the buildResponse function, w.Header().Set("Content-Type", "application/json") needs to come before w.WriteHeader(resp.statusCode)

    opened by patrickjmcd 2
  • Missing previous hash

    Missing previous hash

    Looks like you're not supplying the previous hash when mining?

    https://github.com/crisadamo/gochain/blob/fc3aa97147b0634d043c56db4ef6900ee3116cce/handler.go#L100

    Awesome work - this is a really useful resource!

    opened by mschristensen 1
  • Cannot find Package Error

    Cannot find Package Error

    Hi there, I was going through your code. However , i am not able to run the go code.

    When i run : go build -o gochain

    ERROR:

    main.go:6:5: cannot find package "github.com/crisadamo/gochain" in any of: /usr/local/go/src/github.com/crisadamo/gochain (from $GOROOT) ($GOPATH not set

    Please mind that i have just started with this technology. Kindly Help. Good Day!

    opened by honeyjills 1
  • HTTP is slow, switch to rpc

    HTTP is slow, switch to rpc

    Switch form HTTP too RPC to increase the performance of every request and you get a lot of additional features which HTTP don't have.

    This project seems pretty interesting. I can offer you my help to speed up the development process.

    contact me anytime ;)

    opened by donutloop 1
Owner
Cristian Adamo
Cristian Adamo
Go language implementation of a blockchain based on the BDLS BFT protocol. The implementation was adapted from Ethereum and Sperax implementation

BDLS protocol based PoS Blockchain Most functionalities of this client is similar to the Ethereum golang implementation. If you do not find your quest

Yongge Wang 0 Jan 1, 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

Onyeka 1 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

null 19 Sep 25, 2022
A simplified blockchain implementation in Golang

A simplified blockchain implementation in Golang

Ivan Kuznetsov 3.5k Sep 24, 2022
Implementation of blockchain using golang

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

Beam 2 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

Oren Leung 4 Aug 8, 2022
Blockchain implementation with Go

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

Andika Leonardo 2 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

null 0 Apr 4, 2022
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.

null 104 Sep 22, 2022
DERO: Secure, Anonymous Blockchain with Smart Contracts. Subscribe to Dero announcements by sending mail to [email protected] 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

null 273 Sep 25, 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

Edgar Aroutiounian 60 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

Alonso Villegas 33 Sep 9, 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,

Kure 8 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

Frontier 12 Jul 12, 2022
Implementing blockchain using Golang ✔️

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

null 7 May 24, 2022
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

Jonas Ampferl 8 Jul 14, 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

LINE 31 Aug 4, 2022
utreexo blockchain skeleton

sunyata sunyata is a blockchain skeleton. It implements a minimally-functional proof-of-work blockchain, including consensus algorithms, p2p networkin

The Sia Foundation 18 May 24, 2022
OmniFlix Hub is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

OmniFlix Hub is the root chain of the OmniFlix Network. Sovereign chains and DAOs connect to the OmniFlix Hub to manage their web2 & web3 media operations (mint, manage, distribute & monetize) as well as community interactions.

OmniFlix Network 34 Jun 27, 2022