Coder Social home page Coder Social logo

kotlin-blockchain's Introduction

kotlin-blockchain

Kotlin implementation of basic blockchain technology.

Features:

  • Data and storage
  • Mining and block validation
  • Hashing and previous block identification.

Todo:

  • Transaction system
  • Mining rewards
  • Private/Public key system
  • Alternate consensus methods
  • Secure communication methods
// Creates a new blockchain and initializes it with a "Genesis Block"
val bc = Blockchain(Block("Genesis Block", "", System.currentTimeMillis()))

// Creates a new block to add to the chain.
val block = Block("Hello Blockchain!", bc.blockchain[bc.blockchain.size -1].hash, System.currentTimeMillis())

// Mines block to verify it.
block.mine("00000")

// Adds verified block to the blockchain.
bc.blockchain.add(block)

Example Output:

Creating blockchain with genesis block.
Creating new block.
Block: Data: Hello Blockchain! Previous Hash: c93742f678e8beb33f4b6b80f3a50cabe77513f97081c9fe587d683f3a1cbfa7 Timestamp: 1644266765325
Unverified block hash: 1c85faeed128b7604b9e31257b13a4fbcce03715c200205d983b06bcda8d7705
Attempting to mine block.
Successfully mined block!
Calculating hash took 763541 attempts.
Verified block hash: 000000613e4f6ab796a9c3501a01a734e52634732c85ab59630472aaca992e33
Added verified block to blockchain.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.