https://github.com/Savjee/SavjeeCoin
A simple blockchain in Javascript. For educational purposes only.
https://github.com/Savjee/SavjeeCoin
blockchain cryptography wallet
Last synced: 17 days ago
JSON representation
A simple blockchain in Javascript. For educational purposes only.
- Host: GitHub
- URL: https://github.com/Savjee/SavjeeCoin
- Owner: Savjee
- License: mit
- Created: 2017-09-29T11:09:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-15T09:20:47.000Z (about 2 months ago)
- Last Synced: 2025-03-23T03:02:39.635Z (23 days ago)
- Topics: blockchain, cryptography, wallet
- Language: JavaScript
- Homepage:
- Size: 876 KB
- Stars: 1,750
- Watchers: 87
- Forks: 750
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-list - SavjeeCoin
README
SavjeeCoin
[](https://github.com/Savjee/SavjeeCoin/actions/workflows/ci.yml)
[](https://coveralls.io/github/Savjee/SavjeeCoin?branch=master)
[](https://github.com/Savjee/SavjeeCoin/issues)
[](https://github.com/Savjee/SavjeeCoin/pulls)
[](/LICENSE)---
*⚠️ 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### 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.```js
const EC = require('elliptic').ec;
const ec = new EC('secp256k1');const myKey = ec.genKeyPair();
```The `myKey` object now contains your public & private key:
```js
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:```js
const {Blockchain, Transaction} = require('savjeecoin');const myChain = new Blockchain();
```### Adding transactions
```js
// Transfer 100 coins from my wallet to "toAddress"
const tx = new Transaction(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:
```js
myChain.minePendingTransactions(myKey.getPublic('hex'));
```---
## 📽 Video tutorial
This source code comes from [my video series on YouTube](https://www.youtube.com/watch?v=zVqczFZr124&list=PLzvRQMJ9HDiTqZmbtFisdXFxul5k0F-Q4). You can check them here:| Video 1: Simple implementation | Video 2: Adding Proof-of-work |
:-------------------------:|:-------------------------:
[](https://www.youtube.com/watch?v=zVqczFZr124) | [](https://www.youtube.com/watch?v=HneatE69814)
| Video 3: Mining rewards & transactions | Video 4: Signing transactions |
[](https://www.youtube.com/watch?v=fRV6cGXVQ4I) | [](https://www.youtube.com/watch?v=kWQ84S13-hw)
| Video 5: Building a front-end in Angular
[](https://www.youtube.com/watch?v=AQV0WNpE_3g) |