• Stars
    star
    1,726
  • Rank 27,025 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple blockchain in Javascript. For educational purposes only.

Project logo

SavjeeCoin

.github/workflows/ci.yml Coverage Status GitHub Issues GitHub Pull Requests 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

๐Ÿ 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.

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

const myKey = 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');

const myChain = new Blockchain();

Adding transactions

// 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:

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 implementation Video 2: Adding Proof-of-work
Video 3: Mining rewards & transactions Video 4: Signing transactions
Video 5: Building a front-end in Angular

More Repositories

1

home-energy-monitor

ESP32-based Home Energy Monitor
TypeScript
219
star
2

button-text-card

Custom, "neumorphism" Lovelace card
TypeScript
122
star
3

savjeecoin-frontend

Angular app to visualize & interact with a blockchain
TypeScript
70
star
4

bearclaw

Menubar app to quickly create new notes in Bear
Objective-C
61
star
5

savjee.be

Source code of my Eleventy-powered website
HTML
43
star
6

yt-spam-classifier

Using TensorFlow to automatically filter crypto-related spam comments on YouTube.
Jupyter Notebook
39
star
7

google-sheets-wrapper

Lightweight wrapper around the official Google Sheets API that makes it easy to read/write rows
TypeScript
37
star
8

arduino-aws-iot-starter-template

Arduino code to connect ESP32 with AWS IOT (using MQTT and ArduinoJson)
C++
27
star
9

static-social-buttons

Static Social Buttons for Sharing and Tweeting
JavaScript
19
star
10

static-website-hosting-benchmark

17
star
11

trello-weekmenu-lambda

Meal planning with Trello and AWS Lambda
JavaScript
17
star
12

jsTixClock

A Tix Clock written in Javascript
11
star
13

php-backblaze-b2-uploader

PHP Class that allows you to upload files to Backblaze B2
PHP
11
star
14

svg2pdf

CLI tool to batch convert SVG files to PDF.
JavaScript
9
star
15

Xavier-s-Anagram-Solver

Anagram solver written in PHP.
PHP
8
star
16

3dmon

Simple 3D print progress monitor (for Home Assistant)
Python
6
star
17

OneHighlighter

CSS
6
star
18

eleventy-plugin-bibtex

Converts Bibtex references to APA notation in HTML
JavaScript
5
star
19

anagram-solver

Serverless anagram solver powered by Cloudflare Pages and R2
TypeScript
4
star
20

trash-pickup-belgium

Library to fetch trash pickups in Belgium (Ophaalkalender)
JavaScript
4
star
21

TwoFactorHelper

Safari Extension
Swift
3
star
22

trello-todo

Node.js script that moves Trello cards when they're almost due
JavaScript
3
star
23

xaviers-bitbar-plugins

My plugins for BitBar (written in node.js)
JavaScript
2
star
24

shell-scripts

Some shell-scripts I use
Shell
1
star
25

independent-zipper

Create independent zip archives of a given size
Python
1
star
26

arduino-pca9551

C++
1
star
27

energy-prices-api

TypeScript
1
star
28

dokuwiki-s3-backup

PHP script to backup a DokuWiki site to Amazon S3
PHP
1
star
29

docker-s3website-git-ftp-deploy

Dockerfile
1
star
30

dotfiles

JavaScript
1
star