npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

basic-blockchain

v0.0.4

Published

A basic blockchain implementation

Downloads

3

Readme

Basic Blockchain

A very basic blockchain written in JavaScript

An online blockchain demo.

The concept

A blockchain is a data structure like linked lists with a growing set of nodes or blocks. In a blockchain, each node is called a "block" and each block has an index, timestamp, hash of itself, hash of the previous block and some data.

The hash of each block gives it a unique identity like a fingerprint. A block's hash is generated only once when the block is created and it is generated using the values of all the other attributes of the block. Therefore, if any of the values are changed, the hash will no more be valid and hence the entire block will be invalidated. The calculation of the hash must be reproducable for verification purposes, i.e. a hash function for a given set of values must produce the same hash.

To actually link the blocks together to make a blockchain that cannot be tampered with, each block stores the hash of the previous block. Thus, if the hash of a single block changes, the chain will be broken and given that the last known valid block is now de-linked from the origin, the entire chain will be invalidated.

Mining

A cryptocurrency blockchain implementation has a concept of mining, whereby the hash of a block needs to fulfill certain criteria, e.g. the hash must start with 4 zeros or the hash must be a valid natural number under a certain value. To enable searching for a hash that meets this criteria, an additional flexible parameter called a nonce is added. A simple implementation might use a number as a nonce so that mining is simply looping over all possible numbers to find a fitting hash.

Moreover, a crypocurrency implementation also has the flexibility of choosing which transactions to group into a single block thereby enabling more options for mining.

Distributed verification

A cryptocurrency blockchain implementation also has it's entire blockchain replicated over many different peers. Not all peers have the full chain, as it is enough to keep only a recent portion of the chain for verification purposes. Most importantly, whoever has the longest chain is determined to have the correct copy of the blockchain!

Note that in a network like Bitcoin, the computational complexity of mining a block steadly increases so that it takes 10 minutes to mine a block. This computational complexity is known as difficulty and it could be as simple as increasing the amount of leading zeros that a hash needs to require to fulfill the mining criteria.

Rewards

In a cryptocurrency implementation, each block in a blockchain essentially stores a list of transactions. However, in order for someone to spend money, they need to initially get it. In the bitcoin world, this is known as a coinbase transaction.

Moreover, in order to make it lucrative for miners to spend the effort in mining blocks, each successfully mined block results in some reward for the miner.