-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (30 loc) · 1.3 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { Blockchain, Transaction } = require('./blockchain');
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
// Your private key goes here
const myKey = ec.keyFromPrivate('7c4c45907dec40c91bab3480c39032e90049f1a44f3e18c3e07c23e3273995cf');
// From that we can calculate your public key (which doubles as your wallet address)
const myWalletAddress = myKey.getPublic('hex');
// Create new instance of Blockchain class
const Pucunia = new Blockchain();
// Mine first block
Pucunia.minePendingTransactions(myWalletAddress);
// Create a transaction & sign it with your key
const tx1 = new Transaction(myWalletAddress, 'address2', 100);
tx1.signTransaction(myKey);
Pucunia.addTransaction(tx1);
// Mine block
Pucunia.minePendingTransactions(myWalletAddress);
// Create second transaction
const tx2 = new Transaction(myWalletAddress, 'address1', 50);
tx2.signTransaction(myKey);
Pucunia.addTransaction(tx2);
// Mine block
Pucunia.minePendingTransactions(myWalletAddress);
console.log();
console.log(`Balance of xavier is ${Pucunia.getBalanceOfAddress(myWalletAddress)}`);
// Uncomment this line if you want to test tampering with the chain
// savjeeCoin.chain[1].transactions[0].amount = 10;
// Check if the chain is valid
console.log();
console.log('Blockchain valid?', Pucunia.isChainValid() ? 'Yes' : 'No');