How to create a Genesis Block for a new Blockchain with Node.js

How to create a Genesis Block for a new Blockchain with Node.js

To start creating a new coin with the Proof of Work consensus algorithm. You need to create a Genesis Block. This's Lib support create Genesis Block for Bitcoin, Litcoin, Dash, X11, X13, X15, X17, Geek, Quark, Keccak, Qubit, NeoScrypt...

To start creating a new coin with the Proof of Work consensus algorithm. You need to create a Genesis Block. This's Lib support create Genesis Block for Bitcoin, Litcoin, Dash, X11, X13, X15, X17, Geek, Quark, Keccak, Qubit, NeoScrypt, Scrypt...

Options:

-t TIME, --time=TIME  the (unix) time when the genesisblock is created
-z TIMESTAMP, --timestamp=TIMESTAMP the pszTimestamp found in the coinbase of the genesisblock
-n NONCE, --nonce=NONCE the first value of the nonce that will be incremented when searching the genesis hash
-a ALGORITHM, --algorithm=ALGORITHM the PoW algorithm: [x11|neoscrypt|quark|qubit|keccak|lyra2re]
-p PUBKEY, --pubkey=PUBKEY the pubkey found in the output script
-v VALUE, --value=VALUE the value in coins for the output, full value (exp. in bitcoin 5000000000 - To get other coins value: Block Value * 100000000)
-b BITS, --bits=BITS the target in compact representation, associated to a difficulty of 1
git clone https://github.com/nasa8x/node-genesis-block.git genesis-block
cd genesis-block
npm install
node genesis -a x11 -z "Don't work for weekends, work for our goals - 18/Jan/2018." -p "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"
algorithm: x11
pzTimestamp: Don't work for weekends, work for our goals - 18/Jan/2018.
pubkey: 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f
bits: 504365040
time: 1521537891
merkle root hash: 77fc7d6cfbc4ec91703444a515955092d4b7c04dbb8f23be59deb42a39ec0057
Searching for genesis hash...
nonce: 1827816
genesis hash: 0000084e98003628c45719136940cf7068805f4024419a51d6259fb676c299da

After creating the Genesis Block, change chainparams.cpp.

algorithms
x11
x13
x15
x16r
nist5
neoscrypt
scrypt
keccak
quark
bcrypt
skein
groestl
groestlmyriad
blake
fugue
qubit
hefty1
shavite3
cryptonight
boolberry
yescrypt
fresh

Source code: https://github.com/nasa8x/node-genesis-block

Script for Live Bitcoin Price Ticker using Websockets

Script for Live Bitcoin Price Ticker using Websockets

Websockets are just part of the equation. Executing real-time trades, collecting historical order book snapshots, and managing exchange accounts is all part of the API.

Websockets are just part of the equation. Executing real-time trades, collecting historical order book snapshots, and managing exchange accounts is all part of the API.

A 5-minute tutorial to connect to cryptocurrency exchange websockets.

Check the time - I have 5 minutes to get you connected to a cryptocurrency exchange’s websocket.

That’s a bold assertion, so let’s not waste any time.

Install Libraries

Before we can write our Python script to connect to exchange websockets, we need to install a library. Yes, exactly one library.

Run the following command to install Shrimpy:

pip install shrimpy-python

1 minute down - already 20% done.

Generate API Keys

After installing the Shrimpy Python Library, register for a Shrimpy Developer API account. This service will be used to access the exchange websockets.

Once you’ve signed up for an account, create a new master key. The master key is how you sign requests and access crypto market data. Save the public and private keys for later use. Make sure to enable “data” permissions on these keys. Some data which is available through the APIs includes candlestick (OHLCV) data, historical order book snapshots, and live trade data.

3 minutes passed - Uh oh, we haven’t even started coding yet.

The Code

Stretch those fingers because we’re about to set a new record for the fastest time anyone has ever connected to a crypto exchange websocket.

Library Import

The Shrimpy library has already been installed, so import it into your script.

import shrimpy

Define Handler

To receive data out of the websocket, we need to create a handler. This handler will simply print the price of each trade which is received through the trade websocket.

Since we can receive multiple trades per message, we will only consider the last trade in the message to be the current ticker price.

def error_handler(err):
    print(err)

def handler(msg):
    ticker = msg['content'][len(msg['content']) - 1]['price']
    print(ticker)

Client Creation

Create a client object by calling into the Shrimpy library. Don’t forget to first get the token which is required to create the client. You can get this client by creating an API client, which is created by passing in your public and private API keys. This will help you manage your websocket connection and subscriptions.

public_key = '6d73c2464a71b94a81aa7b13d...'
private_key = 'e6238b0de3cdf19c7861f8e8f5d137ce7113ac1e884b191a14bbb2...'

api_client = shrimpy.ShrimpyApiClient(public_key, private_key)
raw_token = api_client.get_token()
client = shrimpy.ShrimpyWsClient(error_handler, raw_token['token'])

4 minutes now - it’s going to be close.

Declare Subscribe Data

Before we can subscribe to a websocket stream, we must define the subscription for which we want to connect.

subscribe_data = {
    "type": "subscribe",
    "exchange": "binance",
    "pair": "btc-usdt",
    "channel": "trade"
}

Connect Websocket

Start processing the Shrimpy websocket stream by subscribing to the channel.

client.connect()
client.subscribe(subscribe_data, handler)

… and 5 minutes - game, set, match.

Note: You can subscribe to 100 different channels per client. Shrimpy allows each IP to manage up to 10 clients for a total of 1,000 channels per IP.

Just like that, you are now live streaming the latest trade data from Binance. In the handler we defined, that data is parsed to only extract the price at which each trade was executed. That allows us to print the tick-by-tick price of the cryptocurrency at this exact moment.

Disconnect Websocket

Once you’ve finished collecting data, disconnect the client.

client.disconnect()

After connecting to the websocket, you will begin to see price data stream in real time.

Putting it all Together

That was quick, so let’s take a moment to regroup and get a full picture of what we just accomplished.

In the last 5 minutes, we leveraged the Shrimpy APIs and connected to the trade websocket for a crypto exchange. This allowed us to get the real-time ticker price for an asset.

# import the Shrimpy library for crypto exchange websockets
import shrimpy

# a sample error handler, it simply prints the incoming error
def error_handler(err):
    print(err)

# define the handler to manage the output stream
def handler(msg):
    # multiple trades can be returned in each message, so take the last one
    ticker = msg['content'][len(msg['content']) - 1]['price']
    print(ticker)

# input your Shrimpy public and private key
public_key = '6d73c2464a71b94a81aa7b13d...'
private_key = 'e6238b0de3cdf19c7861f8e8f5d137ce7113ac1e884b191a14bbb2...'

# create the Shrimpy websocket client
api_client = shrimpy.ShrimpyApiClient(public_key, private_key)
raw_token = api_client.get_token()
client = shrimpy.ShrimpyWsClient(error_handler, raw_token['token'])

# construct the subscription object
subscribe_data = {
    "type": "subscribe",
    "exchange": "binance",
    "pair": "btc-usdt",
    "channel": "trade"
}

# connect to the Shrimpy websocket and subscribe
client.connect()
client.subscribe(subscribe_data, handler)

# disconnect from the websocket once data collection is complete
client.disconnect()

Now, Binance isn’t the only exchange supported by Shrimpy and the btc-usdt pair isn’t the only trading pair.

The Shrimpy APIs support 17 different exchanges and over 1,300 markets. Each of the most prominent exchanges can be accessed through a simple consolidated websocket API.

Not only that, websockets are just part of the equation. Executing real-time trades, collecting historical order book snapshots, and managing exchange accounts is all part of the API. You can find the full documentation here.

End

Users are able to configure a custom cryptocurrency portfolio and implement a passive rebalancing strategy, removing the hassle of having to actively trade crypto. Shrimpy’s Developer Trading API is a unified way to integrating trading functionality across every major exchange. Collect historical market data, access real-time websockets, execute advanced trading strategies, and manage an unlimited number of users.

Thank for reading !

Top Collection NodeJS Frameworks for Developers in 2020

Top Collection NodeJS Frameworks for Developers in 2020

Node.js is an open-source, cross-platform runtime environment built on Chrome’s V8 javascript engine. The event-driven, non-blocking I/O model makes the NodeJS framework an extremely lightweight and efficient web application.

Node.js is an open-source, cross-platform runtime environment built on Chrome’s V8 javascript engine. The event-driven, non-blocking I/O model makes the NodeJS framework an extremely lightweight and efficient web application.

As a developer, one gets to smoothly use the same language for both client–side and server–side scripting and this unique facility has increased the quick adoption of NodeJS frameworks by many developers across the globe in building web applications of any size.

Since it’s been launched in 2009 as a tool for building scalable, server-side web applications it has brought about exponential growth in its usage.

In addition, Node facilitates quick prototyping in building unique projects.

Let’s check out this list of 10 Top NodeJS Frameworks:

1. Hapi.JS

Hapi is a powerful and robust framework that is used for developing APIs. The well-developed plugin system and various key features such as input validation, configuration-based functionality, implement caching, error handling, logging, etc. make the Hapi one of the most preferred frameworks. It is used for building useful applications and providing technology solutions by several large-scale websites such as PayPal, Disney.

Hapi builds secure, powerful, and scalable applications with minimal overhead and out-of-the-box functionality

Hapi is a configuration-driven model built to control web server operations. It has the unique function of being able to create a server on a specific IP , and has functions such as " onPreHandler ", we can process the request by intercepting the request and preprocessing the request before it is completed.

2. Express.JS

Express.js was built by TJ Holowaychuk, one of the members of the core Node project team. A large community backs this framework, so it has the advantages of continuous updates and reforms of all the core features. This is a minimalist framework that is used to build a number of mobile applications and APIs.

Express is a minimal and flexible Node.JS web application framework providing a robust set of features

It’s robust API allows users to configure routes to send/receive requests between the front-end and the database (acting as a HTTP server framework).

A good advantage with express is how it supports a lot of other packages and other template engines such as Pug, Mustache, EJS and a lot more.

3. Socket.io

It is used for building real-time web applications. It’s a Javascript library that allows the bidirectional data flow between the web client and server. Asynchronous data I/O, binary streaming, instant messaging are some of the most important features of this framework.


Socket the fastest and reliable real-time engine

4. Total.JS

Total.js is a modern and modular NodeJS supporting the MVC architecture. Angular.js, Polymer, Backbone.js, Bootstrap and other client–side frameworks are fully compatible with this framework. This framework is totally extensible and asynchronous. The fact that it does not require any tools such as Grunt to compress makes it easy to use. It also has NoSql embedded in it and supports array and other prototypes.

Total.js has some really beautiful versions like the Total.js Eshop, which contains a user interface optimized for mobile devices, and it is downloadable by all premium members. Eshop is one of the best Node.js e-commerce system. This is because of its many versions of unique content management system(CMS).

5. Sail.JS

This MVC framework has become very popular with NodeJS developers and this framework has gained traction through the development of chat applications, dashboards and multiplayer games. It is most famous for building data-driven APIs. It uses waterline for object-related mapping and db solutions. This framework uses Express.js for handling HTTP requests and is built upon Node.js.

Its compatibility with Grunt modules, including LESS, SASS, Stylus, CoffeeScript, Jade, Dust makes it an ideal candidate for browser-based applications.

Sail is highly compatible with several front-end platforms. Developers have enough freedom to their development while implementing this framework.

6. Derby

This is an MVC framework that is used for creating real-time mobile and web applications. Derby’s Racer, a real-time data synchronization engine for Node.js allows multi-site, real-time concurrency and data synchronization across clients and servers. The racer optimizes conflict resolution and allows real-time editing of the application by leveraging the ShareJS.

Derby is a full-stack framework for writing modern web applications

Derby is an open-source framework based on MVC structure and it is a full-stack NodeJS web framework. Derby is considered ideal for developing real-time collective applications. Using DerbyJS , developers can easily add customized codes and build real-time and effective custom made websites.

7. Meteor.JS

One of the fundamentally most used NodeJS frameworks is Meteor.JS. And this list would remain incomplete if we didn’t mention the MeteorJS framework. This is a full-stack framework of NodeJS which allows users to build real-time applications.

It is used to create both mobile and web-based javascript applications.

Backed by a huge community of developers, tutorials, custom packages and documentation, this framework is used to create some great web and mobile applications for only Javascript only.

8. Loopback

Loopback is a highly-extensible API framework that allows the user to create such APIs that can work with any kind of web client and can be easily bridged to backend sources. This new age modern application comes with complex integration. With Loopback being an open-source framework, the user can create dynamic REST APIs with a minimum or no knowledge of coding.

Highly extensible NodeJS framework for building APIs and microservices

Loopback permits developers to create SDKs and API documentation. This is possible due to widget-API explorer that comes in default with loopback.

Also, it comes with model-relation-support, third party login and storage service, API swagger, better user management policy

9. Koa

Koa was created by the same team that created Express.js and it is often referred to as the next-generation NodeJS framework. Koa is unique in the fact that it uses some really cool ECMAScript(ES6) methods that have not even landed in some browsers yet. It allows you to work without callbacks while providing you with an immense increase in error handling.

It requires a NodeJS version of at least 0.11 or higher.

KoaJS supports syn/await keywords and helps to manage the codes neatly.

Also, it doesn’t pack any bundle of middleware in the core. That makes server writing with Koa faster and enjoyable. KoaJS comes with more options for customization. It allows you to work with applications from scratch where developers can add those features only which they need.

10. NestJS

NestJs is a framework built with Node.js, It is used for building efficient, scalable Node.js server-side applications. Nest uses progressive JavaScript and is written with TypeScript. Being built with TypeScript means that Nest comes with strong typing and combines elements of OOP(Object Oriented Programming), FP(Functional Programming) and FRP(Functional Reactive Programming).

Advantages of the NodeJS framework

NodeJS Framework is now emerging as the most commonly used development framework for building frontend and backend for web applications. And it is the most preferred environment for custom web development. Let’s check some of the major advantages of NodeJS Framework:

  • Real-time working environment
  • Simple coding experience
  • Seamless data streaming
  • Same code pattern throughout development
  • User-friendly
Final analysis

After reading this article, we can of course understand that which framework to use depends entirely on the type of website and web application we want to build. The list of frames is endless and is everywhere in the JavaScript community.

All you need to know about NodeJS Development (FAQ)

All you need to know about NodeJS Development (FAQ)

NodeJS Development FAQ: What is Nodejs, features of Nodejs, Nodejs modules, Types of API functions in Nodejs, Role of REPL in Nodejs, Benefits of nodejs, Difference between Angular JS and Node JS

Did you know that top businesses like #Netflix, #Reddit, #eBay, #Slack and #twitter all use NodeJS? Hosting Tribunal has also enumerated that a cool 85% use #NodeJS for #webappdevelopment. Here All you need to know about #NodeJSDevelopment (FAQ)-