Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsChain

For Educational Purpose only

Clone repository

git clone https://github.com/hitesharma/jsChain.git

cd jsChain

Generate a keypair

const EC = require("elliptic").ec;
const ec = new EC("secp256k1");

const myKeyPair = ec.genKeyPair();

The myKeyPair object contains the public & private key:

console.log("Public key:", myKeyPair.getPublic("hex"));
console.log("Private key:", myKeyPair.getPrivate("hex"));

Create blockchain instance//Getting hash of latest block

const { Blockchain } = require("./src/blockchain");
const { Transaction } = require("./src/transaction");

const myChain = new Blockchain();

Add transactions

// Transfer 10 coins from my wallet address to `toAddress`
const tx = new Transaction(myKeyPair.getPublic("hex"), "toAddress", 10);

tx.signTransaction(myKeyPair);

myChain.addTransaction(tx);

Complete Pending Transactions and Mine Block

myChain.minePendingTransactions(myKeyPair.getPublic("hex"));

Check wallet Balance

console.log('Wallet's balance: ', myChain.getBalance(myKeyPair));

Get latest Block

console.log(`Latest block's Hash: ${myChain.getLatestBlock()});

Verify Blockchain

console.log("Verify Chain: ", myChain.verifyChain() ? "Yes" : "No");

About

Building a blockchain in javascript to understand how cryptography, blockchain and DLT works

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages