Skip to content

The Client that consumes the Blockstream Satellite API

Notifications You must be signed in to change notification settings

obbap1/blockstream-js-client

Repository files navigation

Blockstream JS Client 🙂

Overview

Find the Documentation for the Blockstream Satellite API here

Install

npm install blockstream-js-client

Usage

Based on the node environment, this package will shuttle between the main network or the test network.

const B = require('blockstream-js-client');

// Create an Order on the main or test blockstream network
const { auth_token, uuid } = await B.createOrder({
  bid: '10000', // Amount in millisatoshi
  message: `Paschal's bid for a Tesla`,
});

// Edit Bid
B.increaseBid({
  bid_increase: '4000',
  auth_token,
  uuid,
})
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

// Monitor the status of the order / Get order
B.getOrder({
  auth_token,
  uuid,
})
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

// Delete Order
B.deleteOrder({
  auth_token,
  uuid,
})
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

// Get pending, sent and queued orders
B.getOrders({
  state: 'pending',
})
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

// Get information about the c-lightning node API
B.getInfo()
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

// Subscribe to channels (The only available channel now is the "transmissions" channel)
B.subscribeToChannels(['transmissions'])
  .then((res) => console.log({ res }))
  .catch((error) => console.error(error));

API

This uses some TS definitions.
| means OR
? means OPTIONAL

  • createOrder: Create an Order on the main or test blockstream network

    Usage: createOrder({bid : string, file? : string, message?: string})

    bid: Amount in millisatoshi. Required.
    file: Link to an attachment. Optional.
    message: Message to describe the order. Optional.

    Returns:

     // Success
     {
      error?: false;
      auth_token: string;
      uuid: string;
      lightning_invoice_id: string;
      description: string;
      status: string;
      msatoshi: string | number;
      payreq: string;
      expires_at: number;
      created_at: number;
      metadata: object;
    }
    
    // Error
    {
      error?: true;
      message: string;
    }
  • increaseBid: Increase the bid for a particular order

    Usage: increaseBid({auth_token : string, uuid : string, bid_increase : string })

    auth_token: Authentication token. Required.
    uuid: Universally unique identifier. Required.
    bid_increase: Amount to increase bid by, Millisatoshi. Required.

    Returns:

    // Success
     {
      error?: false;
      auth_token: string;
      uuid: string;
      lightning_invoice_id: string;
      description: string;
      status: string;
      msatoshi: string | number;
      payreq: string;
      expires_at: number;
      created_at: number;
      metadata: object;
    }
    
    // Error
    {
      error?: true;
      message: string;
    }
  • getOrder: Fetch the details of a particular order

    Usage: getOrder({uuid: string, auth_token: string})

    uuid: Required.
    auth_token: Required.

    Returns:

      //Success
      {
          error?: false;
          bid: number | string;
          message_digest: string;
          status: string;
          uuid: string;
          created_at: Date;
          started_transmission_at: Date;
          ended_transmission_at: Date;
          tx_seq_num: string;
          unpaid_bid: number | string;
      }
    
    // Error
      {
          error?: true;
          message: string;
      }
  • getOrders: Get orders that have either been sent, pending or queued.

    Usage: getOrders({state: string, limit?: number, before?: string})

    state: 'pending' | 'sent' | 'queued'. Required.
    limit: Limit length of response. Optional. Defaults to 20.
    before: The date to query with. Optional.

    Returns:

 //Success
   {
      error?: false,
      data: [{
        error?: false;
        bid: number | string;
        message_digest: string;
        status: string;
        uuid: string;
        created_at: Date;
        started_transmission_at: Date;
        ended_transmission_at: Date;
        tx_seq_num: string;
        unpaid_bid: number | string;
      }],
    };

  // Error
    {
        error?: true;
        message: string;
    }
  • deleteOrder: Delete a Particular Order

    Usage: deleteOrder({uuid: string, auth_token: string})

    uuid: Required.
    auth_token: Required.

    Returns:

 //Success
    {
      error?: false,
      message: string,
    }

  // Error
    {
        error?: true;
        message: string;
    }
  • getInfo: Get information about the c-lightning node.

    Usage: getInfo()

    Returns:

 //Success
   {
        error: false;
        id: string;
        alias: string;
        color: string;
        number_of_peers: string | number;
        number_of_active_channels: string | number;
        number_of_inactive_channels: string | number;
        number_of_pending_channels: string | number;
        binding: Array<object>;
        msatoshi_fees_collected: string | number;
        fees_collected_msat: string;
        lightning_directory: string;
        address: Array<object>;
        version: string;
        blockheight: string | number;
        network: string;
    }

  // Error
    {
        error?: true;
        message: string;
    }
  • subscribeToChannels: Subscribe to server-sent event channels. The only channel available now, is the transmissions channel.
    Usage: subscribeToChannels(channels: Array)

    channels: Array of channels. Required.

    Returns:

 //Success
   {
      error?: false,
      message: string,
    }

  // Error
    {
        error?: true;
        message: string;
    }

About

The Client that consumes the Blockstream Satellite API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published