Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 729 Bytes

README.md

File metadata and controls

33 lines (25 loc) · 729 Bytes

BlockChain

Simple BlockChain example

To run use "npm run tsc" and next "node main"

main.ts

//imports
import { Wallet } from './Wallet'
import { Transaction } from './Transaction'
import { Block } from './Block'
import { Chain } from './Chain'

const wallet1: Wallet = new Wallet(); 
const wallet2: Wallet = new Wallet();

let users: Wallet[] = [
    wallet1,
    wallet2
];

let chain: Chain = new Chain();

let last_hash: string = "0";

let block = new Block(4, last_hash);

block.Add(new Transaction(wallet1.id,wallet2.id,Math.round(Math.random()*100)));
block.Add(new Transaction(wallet2.id,wallet1.id,Math.round(Math.random()*100)));
chain.Add(block);

(async () => {
    last_hash = await block.Mine();
})()