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' 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' 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) {
});
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) {
});
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) {
});
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) {
});
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) {
});
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) {
});
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) {
});
Receive smart contract events
blockchainiz.onListenerContract(function (id, event, data) {
});
Receive new Ethereum block event
blockchainiz.onNewBlockEthereum(function (hash) {
});
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/