Skip to content

Commit

Permalink
Merge pull request #193 from blocknative/release/4.4.0
Browse files Browse the repository at this point in the history
Release 4.4.0 (master)
  • Loading branch information
lnbc1QWFyb24 authored Jun 15, 2022
2 parents e79b150 + 61393dd commit e1577b9
Show file tree
Hide file tree
Showing 19 changed files with 586 additions and 318 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ web3.eth.sendTransaction(txOptions).on('transactionHash', hash => {
console.log(`Transaction event: ${transaction.eventCode}`)
})
})
```

#### Address Listener

Expand Down Expand Up @@ -164,3 +165,51 @@ emitter.on('all', transaction => {
## Documentation

For detailed documentation head to [docs.blocknative.com](https://docs.blocknative.com/notify-sdk)

## Multichain SDK (experimental new beta API that may break until it is finalized)

For apps that operate on multiple chains at once, you can use the Multichain SDK which provides a simple interface that abstracts away handling multiple WS connections at once and has a new API for subscribing to events.

## Subscribing to events

Currently a transaction hash or account address can be subscribed to for all events. The `subscribe` method requires an `id`, `chainId` and a `type` and returns an `Observable`. The `Observable` that is returned is specific for events on this subscription and on completion or unsubscribing from the observable will automatically unsubscribe within the SDK. Alternatively you can listen on the global transactions `Observable` at `sdk.transactions$`.

```javascript
import { MultichainSDK } from 'bnc-sdk'

const blocknative = new MultichainSDK({ apiKey: '<YOUR_API_KEY>' })

// subscribe to address events
const addressSubscription = blocknative.subscribe({
id: '0x32ee303b76B27A1cd1013DE2eA4513aceB937c72',
chainId: '0x1',
type: 'account'
})

// can listen to the address subscription directly
addressSubscription.subscribe(transaction => console.log(transaction))

// subscribe to transaction events
const transactionSubscription = blocknative.subscribe({
id: '0xbb1af436fd539a6282c6f45ed900abb5ac95ec435367f61fa8815a61bd2a7211',
chainId: '0x1',
type: 'transaction'
})

// can listen to the transaction subscription directly
transactionSubscription.subscribe(transaction => console.log(transaction))

// or can listen for all transaction events on the global transactions$ observable
blocknative.transaction$.subscribe(transaction => console.log(transaction))
```

## Unsubscribing

To stop listening to events on a transaction hash or account address, call the `unsubscribe` method. If called without a `chainId`, all networks will unsubscribe from the transaction or address. To only unsubscribe on a particular network, pass in the `chainId` of that network.

```javascript
blocknative.unsubscribe({
id: 'transactionHashOrAddress',
chainId: '0x1'
})
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-sdk",
"version": "4.3.0",
"version": "4.4.0",
"description": "SDK to connect to the blocknative backend via a websocket connection",
"keywords": [
"ethereum",
Expand Down
9 changes: 5 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default [
dir: 'dist/iife/',
format: 'iife',
name: 'bncSdk',
globals: ['SturdyWebSocket', 'crypto-es']
globals: ['SturdyWebSocket', 'crypto-es', 'nanoid', 'rxjs']
},
plugins: [
json(),
Expand All @@ -27,7 +27,7 @@ export default [
dir: 'dist/esm/'
}
],
external: ['sturdy-websocket', 'crypto-es'],
external: ['sturdy-websocket', 'crypto-es', 'nanoid', 'rxjs'],
plugins: [
json(),
resolve(),
Expand All @@ -39,12 +39,13 @@ export default [
output: [
{
format: 'cjs',
dir: 'dist/cjs/'
dir: 'dist/cjs/',
exports: 'named'
}
],
plugins: [
json(),
resolve(),
resolve({ preferBuiltins: true }),
commonjs({ include: /node_modules/ }),
typescript({ useTsconfigDeclarationDir: true, clean: true })
]
Expand Down
6 changes: 3 additions & 3 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createEmitter } from './utilities'
import { Emitter, Ac } from './interfaces'
import Blocknative from '.'
import { Emitter, Ac } from './types'
import SDK from '.'

function account(
this: Blocknative,
this: SDK,
address: string
): { emitter: Emitter; details: { address: string } } {
if (this._destroyed)
Expand Down
6 changes: 3 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Subject } from 'rxjs'
import { take, timeout } from 'rxjs/operators'
import Blocknative from '.'
import { Config, Emitter } from './interfaces'
import { Config, Emitter } from './types'
import { createEmitter } from './utilities'
import SDK from '.'

function configuration(
this: Blocknative,
this: SDK,
config: Config
): Promise<string | { details: { config: Config }; emitter?: Emitter }> {
if (this._destroyed) {
Expand Down
5 changes: 3 additions & 2 deletions src/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventObject } from './interfaces'
import SDK from '.'
import { EventObject } from './types'

function event(this: any, eventObj: EventObject): void {
function event(this: SDK, eventObj: EventObject): void {
if (this._destroyed)
throw new Error(
'The WebSocket instance has been destroyed, re-initialize to continue making requests.'
Expand Down
Loading

0 comments on commit e1577b9

Please sign in to comment.