Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

BlockIo

This nodejs module is the official reference SDK for the Block.io payments API. To use this, you will need the Bitcoin, Litecoin or Dogecoin API key(s) from block.io. Go ahead, sign up :)

Installation

Install the package using npm:

npm install block_io

Support for older node.js versions

Currently, only node.js versions 10.0 and higher are supported.

For node.js < 10.0.0, please use: npm install block_io@2.0.3

For node.js < 5.10.0, please use: npm install block_io@1.0.9-5

Usage

It's super easy to get started:

// load this library
const BlockIo = require('block_io');

// instantiate a client
const block_io = new BlockIo('API_KEY');

async function example() {
  try {
    // print the account balance
    let balance = await block_io.get_balance();
    console.log(balance);

    // print all addresses on this account
    let addresses = await block_io.get_my_addresses();
    console.log(addresses);

    // withdrawal; we specify the PIN here
    let withdraw = await block_io.withdraw({
      pin: 'SECRET_PIN',
      from_labels: 'label1,label2',
      to_label: 'label3',
      amount: '50.0'
    });
    console.log(withdraw);

  } catch (error) {
    console.log("Error:", error.message);
  }
}

example();

Promises

Since v3.0.0, all methods return promises, like so:

block_io.get_balance()
        .then(data => console.log(JSON.stringify(data)))
        .catch(error => console.log("Error:", error.message));

Callbacks

For backward compatibility, callback-style method calls are supported too. Just add a callback function/lambda as the last argument.

block_io.get_balance((error, data) => {
  if (error) return console.log("Error:", error.message);
  console.log(JSON.stringify(data));
}

block_io.withdraw({
  pin: 'SECRET_PIN',
  from_labels: 'label1,label2',
  to_label: 'label3',
  amount: '50.0'
}, function (error, data) {
  if (error) return console.log("Error:", error.message);
  console.log(JSON.stringify(data));
});

For more information, see Node.js API Docs. This client provides a mapping for all methods listed on the Block.io API site.

Configuration

To change behavior of the block_io client, attributes can be passed to the class at instantiation time, in the form of an object.

The following attributes are supported:

const config = {
  api_key: "YOUR_API_KEY",
  version: 2,              // REST API version to use. Default: 2
  options: {
    allowNoPin: false,     // Allow ommission of PIN for withdrawal. This makes
                           // withdrawal functions return inputs to sign
                           // outside of the client, rather than sign them
                           // intrinsically. This is useful when interfacing
                           // with hardware wallets and HSMs. Default: false.

    lowR: true,            // Sign with a low R value to save a byte and
                           // make signature size more predictable, at the
                           // cost of more CPU time needed to sign transactions.
                           // Default: true

  }
}

const block_io = new BlockIo(config);

Contributing

  1. Fork it ( https://github.com/BlockIo/block_io-nodejs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Testing

We use tape for unit and integration tests. To run the unit tests simply run npm test.

To run the integration tests you need to specify BLOCK_IO_API_KEY and BLOCK_IO_PIN environment variables.

DO NOT USE PRODUCTION CREDENTIALS FOR INTEGRATION TESTING!

Integration test syntax:

BLOCK_IO_API_KEY="API_KEY" BLOCK_IO_PIN="SECRET_PIN" node test/integration/api.js
You can’t perform that action at this time.