Skip to content

Subscribe request responses

Elliot Lee edited this page May 6, 2020 · 1 revision

Here is an example of listening for all new transactions:

api.connect().then(() => {

  api.connection.on('transaction', (event) => {

      // Do something useful with `event`
      console.log(JSON.stringify(event, null, 2))
  })

  api.request('subscribe', {
      streams: [ 'transactions' ]
  }).then(response => {
      // response.status was already checked internally by ripple-lib
      // response is always an empty object {} in this case
      console.log('Successfully subscribed')
  }).catch(error => {
      // Handle `error`
  })
})