XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

Is any test that cover trancaction subsription? #921

Closed spirinvladimir closed 6 years ago

spirinvladimir commented 6 years ago

I've tried a source code example from docs. But it does not work for me.

const account = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn' // Replace with the account you want notifications for
api.connect().then(() => { // Omit this if you are already connected

  // 'transaction' can be replaced with the relevant `type` from the table above
  api.connection.on('transaction', (event) => {

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

  api.connection.request('subscribe', {
      accounts: [ account ]
  }).then(response => {
      if (response.status === 'success') {
          console.log('Successfully subscribed')
      }
  }).catch(error => {
      // Handle `error`
  })
})

My setting is:

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' // Public rippled server
});

const account = 'rURcktFyZNvDjCCaS5SBL2i5t4DbJyuebE';

My code for fire trancaction event:

'use strict';
const RippleAPI = require('ripple-lib').RippleAPI;

const api = new RippleAPI({
  server: 'wss://s.altnet.rippletest.net:51233' // Public rippled server
});

const from_address = 'rGNck8iFEePApYgvicW6jd6e543g9dJkFT';
const from_secret = 'sa3uH2UbKJR8bsqQH1zsa98pisb1X';

const to_address = 'rURcktFyZNvDjCCaS5SBL2i5t4DbJyuebE';
const to_secret = 'snLPFBjmvBaYASKgnaiEUTCfL4i9T';

const payment = {
    "source": {
        "address": from_address,
        "maxAmount": {
            "value": "5",
            "currency": "XRP"
        }
    },
    "destination": {
        "address": to_address,
        "amount": {
            "value": "5",
            "currency": "XRP"
        }
    }
};

api.connect().then(() => {
    api.preparePayment(from_address, payment).then(prepared => {
        const {signedTransaction} = api.sign(prepared.txJSON, from_secret);

        api.submit(signedTransaction).then(signedTransaction => {
            const {resultCode, resultMessage} = signedTransaction;

            console.log(resultCode, resultMessage);

            return api.disconnect();
        }).catch(console.error)
    }).catch(console.error)
}).catch(console.error)
intelliot commented 6 years ago

Which version of ripple-lib are you using?

If you're reading the docs for a beta version, you'll need to use a beta version of the library, e.g. 1.0.0-beta.3.

spirinvladimir commented 6 years ago

I was using 0.22.0 it comes from '*' alias from example "my_ripple_experiment". Subscription works for me at 1.0.0-beta.3