How to use the ripple-lib.RippleAPI function in ripple-lib

To help you get started, we’ve selected a few ripple-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ripple / xrpl-dev-portal / content / _code-samples / checks / js / prepareCancel.js View on Github external
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI

// This example connects to a public Test Net server
const api = new RippleAPI({server: 'wss://s.altnet.rippletest.net:51233'})
api.connect().then(() => {
  console.log('Connected')

  const sender = 'rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za'
  const options = {
    // Allow up to 60 ledger versions (~5 min) instead of the default 3 versions
    // before this transaction fails permanently.
    "maxLedgerVersionOffset": 60
  }
  return api.prepareCheckCancel(sender, {
    "checkID": "2E0AD0740B79BE0AAE5EDD1D5FC79E3C5C221D23C6A7F771D85569B5B91195C2"
  }, options)

}).then(prepared => {
  console.log("txJSON:", prepared.txJSON);
github ripple / xrpl-dev-portal / content / _code-samples / checks / js / signCreate.js View on Github external
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI

// Can sign offline if the txJSON has all required fields
const api = new RippleAPI()

const txJSON = '{"Account":"rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za", \
  "TransactionType":"CheckCreate", \
  "Destination":"rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis", \
  "SendMax":"100000000", \
  "Flags":2147483648, \
  "LastLedgerSequence":7835923, \
  "Fee":"12", \
  "Sequence":2}'

// Be careful where you store your real secret.
const secret = 's████████████████████████████'

const signed = api.sign(txJSON, secret)

console.log("tx_blob is:", signed.signedTransaction)
github ripple / js-ilp-plugin-ripple / index.js View on Github external
constructor (options) {
    super()

    this.server = options.server
    this.address = options.address
    this.secret = options.secret
    this.log = options.log || console
    this.sourceSubscriptions = options.sourceSubscriptions
    // this.client = new TransferAPI(this.id, this.credentials, this.log)
    this.api = new RippleAPI({ server: this.server })
    this.connected = false

    // this.client.transferPool.on('expire', function (transfers) {
    //   co(this._rejectTransfers.bind(this), transfers)
    //   .catch(this.onExpireError.bind(this))
    // }.bind(this))

    this.api.on('connected', () => {
      // Ripple API doesn't officially support subscribing to transactions, but
      // we can do it by sending a subscribe request manually.
      this.api.connection.request({
        command: 'subscribe',
        accounts: [this.address]
      }).catch((err) => {
        console.warn('ilp-plugin-ripple: unable to subscribe to transactions: ' +
          (err && err.toString()))
github interledgerjs / moneyd-uplink-xrp / index.js View on Github external
async function validateAddress (server, address) {
  const api = new RippleAPI({ server })
  await api.connect()
  const accountInfo = await api.getAccountInfo(address).catch((err) => {
    if (err.message !== 'actNotFound') throw err
    throw new Error('Address "' + address + '" does not exist on ' + server)
  })
  const { validatedLedger: {
    reserveBaseXRP,
    reserveIncrementXRP
  } } = await api.getServerInfo()

  const minBalance = (+reserveBaseXRP) + (+reserveIncrementXRP) * accountInfo.ownerCount + // total current reserve
    (+reserveIncrementXRP) + // reserve for the channel
    (+Plugin.OUTGOING_CHANNEL_DEFAULT_AMOUNT) +
    1 // extra to cover channel create fee
  const currentBalance = +accountInfo.xrpBalance
  if (currentBalance < minBalance) {
github ripple / xrpl-dev-portal / content / _code-samples / escrow / cancel-escrow.js View on Github external
'use strict'
const RippleAPI = require('ripple-lib').RippleAPI

const myAddr = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn'
const mySecret = 's████████████████████████████'

const myEscrowCancellation = {
  owner: myAddr,
  escrowSequence: 366
}
const myInstructions = {
  maxLedgerVersionOffset: 5
}

const api = new RippleAPI({server: 'wss://s2.ripple.com'})

function submitTransaction(lastClosedLedgerVersion, prepared, secret) {
  const signedData = api.sign(prepared.txJSON, secret)
  console.log('Transaction ID: ', signedData.id)
  return api.submit(signedData.signedTransaction).then(data => {
    console.log('Tentative Result: ', data.resultCode)
    console.log('Tentative Message: ', data.resultMessage)
  })
}

api.connect().then(() => {
  console.log('Connected')
  return api.prepareEscrowCancellation(myAddr, myEscrowCancellation, myInstructions)
}).then(prepared => {
  console.log('EscrowCancellation Prepared')
  return api.getLedger().then(ledger => {
github interledgerjs / moneyd / bin / cleanup.js View on Github external
async function run () {
  const api = new RippleAPI({ server })

  console.log('connecting api...')
  await api.connect()

  console.log('getting account...')
  const res = await api.getAccountInfo(address)
  console.log(chalk.green('balance: '), res.xrpBalance + ' XRP')
  console.log(chalk.green('account: '), address)

  const channels = await api.connection.request({
    command: 'account_channels',
    account: address
  })

  const formatted = table([
    [ chalk.green('index'),
github bitpay / bitcore / packages / bitcore-node / src / modules / ripple / api / csp.ts View on Github external
async getClient(network: string) {
    try {
      if (RippleStateProvider.clients[network]) {
        await RippleStateProvider.clients[network].getLedger();
      }
    } catch (e) {
      delete RippleStateProvider.clients[network];
    }
    if (!RippleStateProvider.clients[network]) {
      const networkConfig = this.config[network];
      const provider = networkConfig.provider;
      const host = provider.host || 'localhost';
      const protocol = provider.protocol || 'wss';
      const portString = provider.port;
      const connUrl = portString ? `${protocol}://${host}:${portString}` : `${protocol}://${host}`;
      RippleStateProvider.clients[network] = new RippleAPI({ server: connUrl });
      await RippleStateProvider.clients[network].connect();
    }
    return RippleStateProvider.clients[network];
  }
github bitpay / bitcore / packages / crypto-wallet-core / src / transactions / xrp / index.ts View on Github external
sign(params: { tx: string; key: Key; }) {
    const { tx, key } = params;
    const txJSON = tx;
    let rippleAPI = new RippleAPI();
    const signedTx = rippleAPI.sign(txJSON, {
      privateKey: key.privKey,
      publicKey: key.pubKey,
    });
    return signedTx;
  }
}
github interledgerjs / moneyd-uplink-xrp / index.js View on Github external
async _rippleApi () {
    if (!this.api) {
      this.api = new RippleAPI({ server: this.pluginOpts.xrpServer })
      await this.api.connect()
    }
    return this.api
  }