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

fail sign #818

Closed TXien closed 6 years ago

TXien commented 6 years ago

i sign a payment, but the error message show:

(node:15532) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): NotConnectedError
(node:15532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

following is my code

const RippleAPI = require('ripple-lib').RippleAPI
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'});
const address = 'rGQM86kJsoFuTzfYPs2PLnami1XD1NEQE6';
  const payment = {
    "source": {
      "address": "rGQM86kJsoFuTzfYPs2PLnami1XD1NEQE6",
      "amount": {
        "value": "0.01",
        "currency": "XRP"
      }
    },
    "destination": {
      "address": "rPHtn8eJRXkt3meL1xc4up64SogDeVapxz",
      "minAmount": {
        "value": "0.01",
        "currency": "XRP"
      }
    }
  };
api.preparePayment(address, payment).then(prepared =>
{
        console.info(prepared);
});
crackcomm commented 6 years ago
(node:15532) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): NotConnectedError

Use catch

api.preparePayment(address, payment).then(prepared => {
  console.info(prepared);
}).catch(err => console.error(err));
TXien commented 6 years ago
const RippleAPI = require('ripple-lib').RippleAPI

//const api = new RippleAPI({server: 'wss://s1.ripple.com:443'});
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'});

const address = 'rGQM86kJsoFuTzfYPs2PLnami1XD1NEQE6';
  const payment = {
    "source": {
      "address": "rGQM86kJsoFuTzfYPs2PLnami1XD1NEQE6",
      "amount": {
        "value": "0.01",
        "currency": "XRP"
      }
    },
    "destination": {
      "address": "rPHtn8eJRXkt3meL1xc4up64SogDeVapxz",
      "minAmount": {
        "value": "0.01",
        "currency": "XRP"
      }
    }
  };
api.preparePayment(address, payment).then(prepared =>
{
        console.info(prepared);
}).catch(err => console.log(err));

result is undefined

[NotConnectedError(undefined)]

crackcomm commented 6 years ago

Ok, you have to connect first:

api.connect().then(() => {
   // ... payment
});

See example.

intelliot commented 6 years ago

@TXien Hopefully the above answer resolved your issue. Feel free to let us know if it did not.

TXien commented 6 years ago

thanks, its resolved.