Releases: blocknative/sdk
Bitcoin Support
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 networkId
s 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 connectiononerror
: Called with all errors that happen within the SDK including WebSocket errorsondown
: Called when the WebSocket connection has gone down. It will get called with aCloseEvent
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 thedestroy
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
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
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 toaccount
,transaction
andunsubscribe
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:
Unsubscribe
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:
Transaction Handler Fix
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
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
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
This is just a minor release that corrects the path that points to the TypeScript definition files.
Changelog:
- Fix typings path (#21)
TypeScript
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 nowtransactionHandlers
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 thetransaction
and theaccount
function. This is used to make sure there is separation between multiple sdk instances using the same WebSocket connection.
Changelog:
- Convert to TypeScript (#17 )