Skip to content

Releases: blocknative/sdk

Bitcoin Support

01 May 05:39
1c80af2
Compare
Choose a tag to compare

This release adds support for monitoring Bitcoin transactions! To start monitoring an address or a transaction on the bitcoin network, you can now set the blockchain via the optional (will default to ethereum) system property in the initialization object:

import BlocknativeSdk from 'bnc-sdk'

const options = {
  dappId: 'Your dappId here',
  networkId: 1,
  system: 'bitcoin'
}

const blocknative = new BlocknativeSdk(options)

The following networkIds are valid for bitcoin:

  • main network: 1
  • testnet network: 2

Once initialized you can watch addresses and transactions in the same way you would when connected to Ethereum with one exception. Bitcoin uses a txid to look up transactions rather than the hash, so pass in the txid of the transaction you would like to watch in to the transaction method.

Also included in this release are added options for getting detailed status updates on the WebSocket connection and better error handling. The following callback functions can be passed in to the initialization options:

  • onopen: Called when the WebSocket first successfully opens the connection
  • onerror: Called with all errors that happen within the SDK including WebSocket errors
  • ondown: Called when the WebSocket connection has gone down. It will get called with a CloseEvent object which has more information on the close event. The SDK will automatically attempt to reconnect, but knowing it is down can be useful.
  • onreopen: Called when the connection has reopened after going down.
  • onclose: Called when the connection has been permanently closed after calling the destroy method (see below)

Example:

import BlocknativeSdk from 'bnc-sdk'

const options = {
  dappId: 'Your dappId here',
  networkId: 1,
  onerror: error => console.log('SDK error', error),
  onopen: () => console.log('SDK is connected'),
  ondown: () => console.log('SDK connection has dropped'),
  onreopen: () => console.log('SDK has re-connected after dropped connection'),
  onclose: () => console.log('SDK has been destroyed')
}

const blocknative = new BlocknativeSdk(options)

Also added to the main API is a destroy method which can be called to close the websocket connection at any time.

The SDK now also handles socket connection drops on Node.js websocket instances properly now via a ping pong method, which the Sturdy WebSocket dependency doesn't take care of.

Changelog:

  • Enhancement: Expose WebSocket Handlers and Handle Node Connection Drops (#52)
  • Enhancement: Linting and Formatting (#55)
  • Feature: Bitcoin Support (#56)
  • Enhancement: WebSocket Handlers (#59)
  • Enhancement: Destroy Method (#60)
  • Fix: onclose method (#62)
  • Fix: Validation (#64)
  • Enhancement: Error Handling (#65)
  • Enhancement: Handle Server Errors (#68)

Split UMD build

17 Apr 01:00
294d12c
Compare
Choose a tag to compare

This release has a small change that separates the UMD build out in to a CJS and IIFEE build so that CJS builds don't need to pay the cost of the IIFE code.

Changelog:

  • Enhancement: Split Build (#49 )

Refactor Socket Connection

25 Mar 04:23
d8a37ce
Compare
Choose a tag to compare

This is a major release with breaking changes that include:

  • An architecture change that creates a separate WebSocket connection for each instance of the SDK that is running in the same client and ensures completely separate state between instances
  • Removal of the clientIndex parameter from the API and also removing it from calls to account, transaction and unsubscribe for a better dev experience.

Changes you need to make when upgrading from 1.x.x to 2.0.0:

  • The SDK is now created from a class instead of a function, requiring the new keyword when instantiating:
// 1.x.x
import blocknativeSdk from 'bnc-sdk'
const blocknative = blocknativeSdk(options)

// 2.0.0
import BlocknativeSdk from 'bnc-sdk'
const blocknative = new BlocknativeSdk(options)
  • The clientIndex parameter has been removed from the API and doesn't need to be included in function calls:
// === watching a transaction === //
// 1.x.x
const { emitter } = blocknative.transaction(blocknative.clientIndex, hash)
// 2.0.0
const { emitter } = blocknative.transaction(hash)

// === watching a account === //
// 1.x.x
const { emitter } = blocknative.account(blocknative.clientIndex, address)
// 2.0.0
const { emitter } = blocknative.account(address)

// === unwatching a transaction === //
// 1.x.x
const { emitter } = blocknative.unsubscribe(blocknative.clientIndex, hash)
// 2.0.0
const { emitter } = blocknative.unsubscribe(hash)

// === unwatching a account === //
// 1.x.x
const { emitter } = blocknative.unsubscribe(blocknative.clientIndex, address)
// 2.0.0
const { emitter } = blocknative.unsubscribe(address)

Changelog:

  • Feature: refactor connection (#46)
  • Bump acorn from 5.7.3 to 5.7.4 (#44)

Unsubscribe

03 Mar 22:34
dddc6da
Compare
Choose a tag to compare

This release adds a new method to the API that allows for unsubscribing from addresses and transaction hashes. To unsubscribe, just call the unsubscribe method and pass the clientIndex and an address or hash that you would like to unsubscribe from:

// unsubscribe from address
blocknative.unsubscribe(blocknative.clientIndex, address)

// unsubscribe from transaction hash
blocknative.unsubscribe(blocknative.clientIndex, hash)

There is also a small fix to the validation of initialization parameters as well.

Changelog:

  • Feature: Add unsubscribe method to API (#39)
  • Fix validation for transactionHandlers (#37)

Transaction Handler Fix

05 Dec 05:34
6b4cd7a
Compare
Choose a tag to compare

In this release, there is just a small fix for a bug to make sure that the transactionHandler is always called for every transaction, even if there isn't an emitter registered for it.

Changelog:

  • Fix transaction handler (#32)

Connection Open

25 Nov 21:48
0170587
Compare
Choose a tag to compare

Just a small update to make sure that sendMessage waits for the connection to be open before sending the message. This ensures that all messages are sent after the connectionId has been sent.

Changelog:

  • Wait for connection open before sending messages (#28)

Type Interface Updates

28 Oct 02:53
1bd8454
Compare
Choose a tag to compare

A small release to update some of the type interfaces so that they are consistent with the interfaces in bnc-notify.

Changelog:

  • Update types to be consistent with Notify (#24)

Typings Fix

24 Oct 02:53
b0afd22
Compare
Choose a tag to compare

This is just a minor release that corrects the path that points to the TypeScript definition files.

Changelog:

  • Fix typings path (#21)

TypeScript

23 Oct 03:20
33a263d
Compare
Choose a tag to compare

In this release, the code base has been completely moved over from vanilla JavaScript to TypeScript.

There are a couple of breaking changes in this release:

  • The initialization options object parameter transactionListeners is now transactionHandlers for consistency with other Blocknative code bases.
  • The returned initialized API now includes a parameter clientIndex which needs to be passed in as the first parameter to both the transaction and the account function. This is used to make sure there is separation between multiple sdk instances using the same WebSocket connection.

Changelog:

  • Convert to TypeScript (#17 )

Typescript Definitions

03 Oct 05:04
5092a79
Compare
Choose a tag to compare

A small update that adds Typescript definitions and some changes to internal logic to handle changes to the server.

Change log:

  • Add Typescript definitions (#13)
  • Handle watch address events (#11)