Skip to content

Commit

Permalink
Merge branch 'jac/fix_examples'
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Nov 16, 2021
2 parents 039973e + 239b15f commit 3354206
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,33 @@ A lightweight JavaScript sdk to connect to the Blocknative backend Ethereum node

### Quick Start (client)

#### Transaction Monitor

```javascript
import WebSocket from 'ws'
import BlocknativeSdk from 'bnc-sdk'
import Web3 from 'web3'

const web3 = new Web3(window.ethereum)
const wsapi_url = 'wss://api.blocknative.com/v0'

const web3 = new Web3(wsapi_url)

// create options object
const options = {
dappId: 'Your dappId here',
dappId: process.env.BN_API_KEY,
ws: WebSocket,
networkId: 1,
transactionHandlers: [event => console.log(event.transaction)]
}

// initialize and connect to the api
const blocknative = new BlocknativeSdk(options)

const txOptions = {
from: "0x7A132e43013cAA14a3744721EF179f1F3d2b3921",
to: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
}

// initiate a transaction via web3.js
web3.eth.sendTransaction(txOptions).on('transactionHash', hash => {
// call with the transaction hash of the transaction that you would like to receive status updates for
Expand All @@ -44,8 +55,41 @@ web3.eth.sendTransaction(txOptions).on('transactionHash', hash => {
emitter.on('all', transaction => {
console.log(`Transaction event: ${transaction.eventCode}`)
})
})

```

#### Address Listener

```javascript
import WebSocket from 'ws'
import BlocknativeSdk from 'bnc-sdk'
import Web3 from 'web3'

const wsapi_url = 'wss://api.blocknative.com/v0'

const web3 = new Web3(wsapi_url)

// create options object
const options = {
dappId: process.env.BN_API_KEY,
ws: WebSocket,
networkId: 1
}

// initialize and connect to the api
const blocknative = new BlocknativeSdk(options)

const address = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"

const { emitter, details } = blocknative.account(address)

emitter.on("all", transaction => {
console.log(transaction)
})
```


## Documentation

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

0 comments on commit 3354206

Please sign in to comment.