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

blockchainiz

v1.4.1

Published

A node library to interact more easily with the Blockchainiz API

Downloads

19

Readme

Build Status Coverage Status

Description

Blockchainiz is a platform to access the blockchain. It is dedicated to banks and insurance companies. This package is a node library to interact more easily with the Blockchainiz API.

Installation

Simply use NPM with the following command:

npm install blockchainiz --save

This will download the package and add an entry in your project's package.json file.

Setup

In your project's source code, you need to start by importing the blockchainiz package and specify the options you want to use:

const blockchainiz = require('blockchainiz')({
  publicKey: 'your public key',
  privateKey: 'your private key',
  useSandbox: true,
});

There are 3 options that you can set. You NEED to specify them in order for the package to work:

Option | Type | Description ------ | ---- | ----------- publicKey | string | Your Blockchainiz public key privateKey | string | Your Blockchainiz private key useSandbox | bool | True to use the sandbox version of the API

Reference REST API

Set the API key set to use

blockchainiz.setKeys(publicKey, privateKey);

Parameter | Type | Description --------- | ---- | ----------- publicKey | string | The public key privateKey | string | The private key

Set the version of the API to use

blockchainiz.useSandbox(shouldUseSandbox);

Parameter | Type | Description --------- | ---- | ----------- shouldUseSandbox | bool | True to use the sandbox. False to use the production version

Get infos about the Bitcoin node

blockchainiz.getInfoNodeBitcoin(function (err, data) {
  // data contains the informations
});

'data' key | Type | Description ---------- | ---- | ----------- version | number | The version number of the Bitcoin node used by the API protocolVersion | number | The Bitcoin protocol version number of the node used by the API blockNumber | number | Number of the last blocked mined on the Bitcoin blockchain difficulty | number | Current difficulty on the Bitcoin network

Get infos about the Ethereum node

blockchainiz.getInfoNodeEthereum(function (err, data) {
  // data contains the informations
});

'data' key | Type | Description ---------- | ---- | ----------- networkProtocolVersion | string | Version of the network protocol of the node used by the API ethereumProtocolVersion | string | Version of the Ethereum protocol of the node used by the API solcVersion | string | Version of the solidity compiler used by the API gasPrice | string | Current gas price in wei blockNumber | number | Number of the most recent block on the Ethereum blockchain

Create a new notary in the API

As of today, only the Bitcoin blockchain can be used to host notaries.

blockchainiz.postNotary(format, data, function (err, data) {
  // data contains the response of Blockchainiz
});

Parameter | Type | Description --------- | ---- | ----------- format | string | Format in which the data is encoded (allowed values: 'hex', 'base64', 'ascii') data | string | The data to notarize

'data' key | Type | Description ---------- | ---- | ----------- txid | string | ID of the transaction

Get a particular notary

blockchainiz.getNotary(format, txid, function (err, data) {
  // data contains the response of Blockchainiz
});

Parameter | Type | Description --------- | ---- | ----------- format | string | Format in which to return the result (allowed values: 'hex', 'base64', 'ascii') txid | string | ID of the transaction on the blockchain

'data' key | Type | Description ---------- | ---- | ----------- data | string | Data notarized in the blockchain status | string | Current status of the transaction. Can be 'mined' or 'not mined' confirmations | number | Number of confirmations for that bloc blockindex | number | Position of the transaction inside the bloc blocktime | number | Timestamp in seconds of when the bloc was mined

blockindex and blocktime won't be included if the notary has not been mined in a bloc yet

Get all the notaries added with a particular key set

blockchainiz.getNotaries(format, function (err, data) {
  // data contains all the notaries
});

Parameter | Type | Description --------- | ---- | ----------- format | string | Format in which to return the result (allowed values: 'hex', 'base64', 'ascii')

The data parameter of the callback contains an array of objects. Each object represents a notary and follows the same format as in the method getNotary.

Add a new smart contract on Ethereum

blockchainiz.postContractEthereumSolidity(sourceCode, parameters, contractName, callbackUrl, function (err, data) {
  // data contains the response of Blockchainiz
});

Parameter | Type | Description --------- | ---- | ----------- sourceCode | string | The source code of the smart contract to upload parameters | array | Array of parameters to pass to the constructor contractName | string | Name of the smart contract to upload in the sources callbackUrl | string | A URL that will be called back when the contract is mined on Ethereum

'data' key | Type | Description ---------- | ---- | ----------- abi | object | The ABI if the contract returned by the solidity compiler id | number | The Blockchainiz ID of the new contract

Get infos about a smart contract added with Blockchainiz

blockchainiz.getContract(id, function (err, data) {
  // data contains the response of Blockchainiz
});

Parameter | Type | Description --------- | ---- | ----------- id | number | Id number of the smart conttract in the Blockchainiz API

'data' key | Type | Description ---------- | ---- | ----------- abi | object | The ABI definition of the contract amount | number | Account of ether in the contract wallet status | string | Status of the contract can be mined or not mined address | string | Address of the contract

amount and address won't be included if the contract has not been mined yet

Call a function on an Ethereum smart contract

blockchainiz.postContractEthereumSolidityFunction(parameters, id, functionName, function (err, data) {
  // data contains the response of Blockchainiz
});

Parameter | Type | Description --------- | ---- | ----------- parameters | array | Array of parameters to pass to the function id | number | ID number of the contract on Blockchainiz functionName | string | Name of the function to call

'data' key | Type | Description ---------- | ---- | ----------- result (optional) | array | The result value of the smart contract function txid (optional) | string | The ID number of the transaction

result will only be present if the function is constant and returns something. txid will only be present if the function is not constant and so trigger an Ethereum transaction

Reference Socket.io

In order to receiver a socket.io event, you must first subscribe to it. More informations on the full documentation of the API: https://www.sandbox.blockchainiz.io/#socket-io

Subscribe to new Ethereum block event

blockchainiz.listenerNewBlockEthereum();

Subscribe to smart contract event

blockchainiz.listenerContract(contractId, eventName);

Parameter | Type | Description --------- | ---- | ----------- contractId | number | Blockchainiz ID number of the contract to listen to eventName | string | Name of the Ethereum event to listen to

Receive error messages

blockchainiz.onErrorText(function (event, error) {
  // event contains the name of the event who triggered the error
  // error contains the error message
});

Receive smart contract events

blockchainiz.onListenerContract(function (id, event, data) {
  // id is the blockchainiz id number of the smart contract
  // event is the name of the Ethereum event received
  // data is the data sent by the Ethereum event
});

Receive new Ethereum block event

blockchainiz.onNewBlockEthereum(function (hash) {
  // hash of the new block
});

Next steps

The documentation of the API itself is available here: https://www.sandbox.blockchainiz.io/

You can sign up for a pair of keys on our website: https://www.blockchainiz.io/