CeamKrier / blockchain-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blockchain with JS

A basic blockchain implementation that uses a proof-of-work consensus algorithm written in javascript.

Transaction

Holds necessary info like who is the sender, receiver and the amount subject to trade.

Structure of transaction data:

{
    meta: {
        state: signed | minable | includedToBlock | failed | verified,
        signature: generated on sign
    },
    data: {
        timestamp: generated on tx creation,
        from: sender address,
        to: receiver address,
        value: amount sent
}

Life-cycle of Transaction

  • signed: Transaction generated, balance of sender controlled and it is adequate to carry out transaction. Transaction signed with transaction.data and the privateKey of sender's wallet. Value saved on transaction.meta.signature.

  • minable: A signed transaction reach to the miner, miner validates signature to be sure the sender is legit. If transaction signature is valid then transaction.meta.state set to minable or it set to failed.

  • includedToBlock: A minable transaction taken by a miner and included its candidate block. Mostly, this selection depends on the transaction fee paid by the sender, higher the fee faster the inclusion into a block, but I skipped that to keep things simple. Then transaction.meta.state set to includedToBlock.

  • verified: Transaction inside a candidate block has mined and added to blockchain, all the transactions inside it will be updated as verified.

  • failed: Transaction failed for a reason and discarded.

About


Languages

Language:JavaScript 100.0%