2013-09-09 14:49:14 -07:00
2013-09-06 15:41:17 -07:00
2013-04-26 08:59:48 +02:00
2013-09-09 14:49:14 -07:00
2013-09-09 13:05:40 -07:00
2013-04-26 09:00:22 +02:00
2013-07-18 07:58:55 +09:00
2013-05-07 20:54:04 +02:00
2013-04-26 09:10:42 +02:00
2013-09-08 17:35:50 -07:00
2013-09-08 18:07:30 -07:00
2013-09-04 17:02:30 -07:00

#Ripple JavaScript Library

npm install ripple-lib

This library can connect to the Ripple network via the WebSocket protocol and runs in Node.js as well as in the browser.

##Getting started

ripple-lib.remote is responsible for managing connections to rippled servers.

var Remote = require('ripple-lib').Remote;

var remote = new Remote({
  trusted:        true,
  local_signing:  true,
  local_fee:      true,
  servers: [
    {
        host:    's1.ripple.com'
      , port:    443,
      , secure:  true
    }
  ]
});

remote.connect(function() {
  /* remote connected */
});

##Calling remote commands

Each remote function returns a Request object. This object is an EventEmitter. You may listen for success or failure events from each request, or provide a callback. Example:

var request = remote.request_server_info();
request.on('success', function(res) {
  //handle success
});
request.on('error', function(err) {
  //handle error
});
request.request();

Or:

remote.request_server_info(function(err, res) {
  if (err) {
    //handle error
  } else {
    //handle success
  }
});

##Commands available

request_server_info([callback])

Returns information about the state of the server. If you are connected to multiple servers and want to select by a particular host, use request.set_server. Example:

var request = remote.request_server_info();
request.set_server('my.hostname');
request.callback(function(err, res) {

});
request.request();

request_ledger(ledger, [opts], [callback])

request_ledger_header([callback])

request_ledger_current([callback])

request_ledger_entry(type, [callback])

request_subscribe(streams, [callback])

Start receiving selected streams from the server.

request_unsubscribe(streams, [callback])

Stop receiving selected streams from the server.

request_transaction_entry(hash, [ledger_hash], [callback])

Searches a particular ledger for a transaction hash. Default ledger is the open ledger.

request_tx(hash, [callback])

Searches ledger history for validated transaction hashes.

request_account_info(account, [callback])

Return information about the specified account.

{
  ledger_current_index: <number>,
  account_data: {
    Account:            <string>,
    Balance:            <number>,
    Flags:              <number>,
    LedgerEntryType:    <string>,
    OwnerCount:         <number>,
    PreviousTxnID:      <string>,
    PreviousTxnLgrSeq:  <number>,
    Sequence:           <number> ,
    index:              <string>
  }
}

request_account_lines(accountID, account_index, current, [callback])

request_account_offers(accountID, account_index, current, [callback])

Return the specified account's outstanding offers.

request_account_tx(opts, [callback])

Fetch a list of transactions that applied to this account.

Options:

  • account
  • ledger_index_min deprecated, -1
  • ledger_index_max deprecated, -1
  • binary false
  • count false
  • descending false
  • offset 0
  • limit
  • forward false
  • fwd_marker
  • rev_marker

request_book_offers(gets, pays, taker, [callback])

Return the offers for an order book as one or more pages.

request_wallet_accounts(seed, [callback])

Return a list of accounts for a wallet.

  • requires trusted remote

request_sign(secret, tx_json, [callback])

Sign a transaction.

  • requires trusted remote

request_submit([callback])

Submit a transaction to the network. This command is used internally to submit transactions with a greater degree of reliability. See Submitting a transaction for details.

request_account_balance(account, ledger, [callback])

Get the balance for an account. Returns an Amount object.

request_account_flags(account, current, [callback])

Return the flags for an account.

request_owner_count(account, current, [callback])

Return the owner count for an account.

request_ripple_balance(account, issuer, currency, current, [callback])

Return a request to get a ripple balance

request_ripple_path_find(src_account, dst_account, dst_amount, src_currencies, [callback])

request_unl_list([callback])

request_unl_add(addr, comment, [callback])

request_unl_delete(node, [callback])

request_peers([callback])

request_connect(ip, port, [callback])

transaction([destination], [source], [amount], [callback])

Returns a Transaction object

##Submitting a transaction

var Remote = require('ripple-lib').Remote;
var Amount = require('ripple-lib').Amount;

var MY_ADDRESS = 'rrrMyAddress';
var MY_SECRET  = 'secret';
var RECIPIENT  = 'rrrRecipient';
var AMOUNT     = Amount.from_human('1XRP');

var remote = new Remote({ /* configuration */ });

remote.connect(function() {
  remote.set_secret(MY_ADDRESS, MY_SECRET);

  var transaction = remote.transaction();

  transaction.payment(MY_ADDRESS, RECIPIENT, AMOUNT);

  transaction.submit(function(err, res) {
    /* handle submission errors / success */
  });
});

###Transaction events

Transaction objects are EventEmitters. They may emit the following events.

  • final Transaction has erred or succeeded. This event indicates that the transaction has finished processing.
  • error Transaction has erred. This event is a final state.
  • success Transaction succeeded. This event is a final state.
  • submitted Transaction has been submitted to the network. The submission may result in a remote error or success.
  • proposed Transaction has been submitted successfully to the network. The transaction at this point is awaiting validation in a ledger.
  • timeout Transaction submission timed out. The transaction will be resubmitted.
  • resubmit Transaction is beginning resubmission.
  • fee_adjusted Transaction fee has been adjusted during its pending state. The transaction fee will only be adjusted if the remote is configured for local fees, which it is by default.
  • abort Transaction has been aborted. Transactions are only aborted by manual calls to #abort.
  • missing Four ledgers have closed without detecting validated transaction
  • lost Eight ledgers have closed without detecting validated transaction. Consider the transaction lost and err/finalize.
Description
A JavaScript/TypeScript API for interacting with the Xahau Ledger in Node.js and the browser
Readme 43 MiB
Languages
TypeScript 97.4%
JavaScript 2.6%