Skip to content

Repository files navigation

Project logo

SavjeeCoin

.github/workflows/ci.ymlCoverage StatusGitHub IssuesGitHub Pull RequestsLicense


⚠️ For education purposes only. This is by no means a complete implementation and it is by no means secure!

Features

  • Simple proof-of-work algorithm
  • Verify blockchain (to prevent tampering)
  • Generate wallet (private/public key)
  • Sign transactions

🏁 Getting Started

Install library

npm install --save savjeecoin

Generate a keypair

To make transactions on this blockchain you need a keypair. The public key becomes your wallet address and the private key is used to sign transactions.

constEC=require('elliptic').ec;constec=newEC('secp256k1');constmyKey=ec.genKeyPair();

The myKey object now contains your public & private key:

console.log('Public key:',myKey.getPublic('hex'));console.log('Private key:',myKey.getPrivate('hex'));

Create a blockchain instance

Now you can create a new instance of a Blockchain:

const{Blockchain, Transaction}=require('savjeecoin');constmyChain=newBlockchain();

Adding transactions

// Transfer 100 coins from my wallet to "toAddress"consttx=newTransaction(myKey.getPublic('hex'),'toAddress',100);tx.sign(myKey);myChain.addTransaction(tx);

To finalize this transaction, we have to mine a new block. We give this method our wallet address because we will receive a mining reward:

myChain.minePendingTransactions(myKey.getPublic('hex'));

📽 Video tutorial

This source code comes from my video series on YouTube. You can check them here:

Video 1: Simple implementationVideo 2: Adding Proof-of-work
Video 3: Mining rewards & transactionsVideo 4: Signing transactions
Video 5: Building a front-end in Angular

About

A simple blockchain in Javascript. For educational purposes only.

Topics

Resources

Stars

1.8k stars

Watchers

83 watching

Forks

Releases

Packages

Used by

Contributors

Languages