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)