New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simplychain

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplychain

Blockchain proof of concept using Javasciprt

latest
Source
npmnpm
Version
1.2.3
Version published
Maintainers
1
Created
Source

Blockchain in Javascript

The blockchain implementation using javascript.

Installation

Using npm:

$ npm install simplychain

How to

// Import the module
const { SimplyChain } = require('simplychain');
// Or import esm module
// import { SimplyChain } from 'simplychain';

// Create your awesome block chain
let myBlockChain = new SimplyChain();

// Get the last appended block in the chain
// because we haven't added any block yet so the only block in the chain is genesis block
let genesisBlock = myBlockChain.lastBlock;

// Check the first block the chain 
console.log(genesisBlock);

// Add transaction 
// A transaction can be any type which you would like to store on the blockcahin
let transaction = {
	from: 'A',
	to: 'B',
	amount: '100'
};
myBlockChain.addTransaction(transaction);

// Get the latest block. This will put all current transactions into a block which can be mined and appended to the chain. 
let block = myBlockChain.pendingBlock;

block.mineSync( () => {
	// proof of work
	let nonce = block.nonce;
	
	// append the latest block to the chain
	myBlockChain.addBlock(nonce);

	// validate the chain is valid
	let valid = myBlockChain.validate();

	console.log('Successfully mined a block!', nonce, valid);
});

Keywords

blockchain

FAQs

Package last updated on 29 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts