1.4.1 • Published 6 years ago

blockchainiz v1.4.1

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

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:

OptionTypeDescription
publicKeystringYour Blockchainiz public key
privateKeystringYour Blockchainiz private key
useSandboxboolTrue to use the sandbox version of the API

Reference REST API

Set the API key set to use

blockchainiz.setKeys(publicKey, privateKey);
ParameterTypeDescription
publicKeystringThe public key
privateKeystringThe private key

Set the version of the API to use

blockchainiz.useSandbox(shouldUseSandbox);
ParameterTypeDescription
shouldUseSandboxboolTrue 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' keyTypeDescription
versionnumberThe version number of the Bitcoin node used by the API
protocolVersionnumberThe Bitcoin protocol version number of the node used by the API
blockNumbernumberNumber of the last blocked mined on the Bitcoin blockchain
difficultynumberCurrent difficulty on the Bitcoin network

Get infos about the Ethereum node

blockchainiz.getInfoNodeEthereum(function (err, data) {
  // data contains the informations
});
'data' keyTypeDescription
networkProtocolVersionstringVersion of the network protocol of the node used by the API
ethereumProtocolVersionstringVersion of the Ethereum protocol of the node used by the API
solcVersionstringVersion of the solidity compiler used by the API
gasPricestringCurrent gas price in wei
blockNumbernumberNumber 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
});
ParameterTypeDescription
formatstringFormat in which the data is encoded (allowed values: 'hex', 'base64', 'ascii')
datastringThe data to notarize
'data' keyTypeDescription
txidstringID of the transaction

Get a particular notary

blockchainiz.getNotary(format, txid, function (err, data) {
  // data contains the response of Blockchainiz
});
ParameterTypeDescription
formatstringFormat in which to return the result (allowed values: 'hex', 'base64', 'ascii')
txidstringID of the transaction on the blockchain
'data' keyTypeDescription
datastringData notarized in the blockchain
statusstringCurrent status of the transaction. Can be 'mined' or 'not mined'
confirmationsnumberNumber of confirmations for that bloc
blockindexnumberPosition of the transaction inside the bloc
blocktimenumberTimestamp 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
});
ParameterTypeDescription
formatstringFormat 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
});
ParameterTypeDescription
sourceCodestringThe source code of the smart contract to upload
parametersarrayArray of parameters to pass to the constructor
contractNamestringName of the smart contract to upload in the sources
callbackUrlstringA URL that will be called back when the contract is mined on Ethereum
'data' keyTypeDescription
abiobjectThe ABI if the contract returned by the solidity compiler
idnumberThe 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
});
ParameterTypeDescription
idnumberId number of the smart conttract in the Blockchainiz API
'data' keyTypeDescription
abiobjectThe ABI definition of the contract
amountnumberAccount of ether in the contract wallet
statusstringStatus of the contract can be mined or not mined
addressstringAddress 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
});
ParameterTypeDescription
parametersarrayArray of parameters to pass to the function
idnumberID number of the contract on Blockchainiz
functionNamestringName of the function to call
'data' keyTypeDescription
result (optional)arrayThe result value of the smart contract function
txid (optional)stringThe 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);
ParameterTypeDescription
contractIdnumberBlockchainiz ID number of the contract to listen to
eventNamestringName 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/

1.4.1

6 years ago

1.4.0

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago