9.1 KiB
#API Reference
(More examples coming soon!)
###In this document:
- Server requests
- Ledger requests
- Transaction requests
- Account requests
- Orderbook requests
- Transaction requests
###Also see:
#Remote options
/* Loading ripple-lib with Node.js */
var Remote = require('ripple-lib').Remote;
/* Loading ripple-lib in a webpage */
// var Remote = ripple.Remote;
var options = { };
var remote = new Remote(options);
A new Remote can be created with the following options:
traceboolean default: false Log all of the events emittedmax_listenersnumber default: 0 Set maxListeners for serverstrustedboolean default: false, if remote is trusted (boolean)local_signingboolean default: truelocal_feeboolean default: true Set whether the transaction fee range will be set locally, see A note on transaction fees)fee_cushionnumber default: 1.2 Extra fee multiplier to account for async fee changes, see A note on transaction fees)max_feenumber default: Infinity Maximum acceptable transaction fee, see A note on transaction feesserversarray Array of server objects of the following form:
{
host: <string>,
port: <number>,
secure: <boolean>
}
or
'wss://host:port'
#Request constructor functions
##Server requests
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.setServer. Example:
var request = remote.request('server_info');
request.setServer('wss://s1.ripple.com');
request.request(function(err, res) {
});
unl_add(addr, comment, [callback])
##Ledger requests
ledger(ledger, [opts], [callback])
ledger_header([callback])
ledger_entry(type, [callback])
subscribe([streams], [callback])
Start receiving selected streams from the server.
unsubscribe([streams], [callback])
Stop receiving selected streams from the server.
##Account requests
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>
}
}
account_lines(accountID, [account_index], [ledger], [callback])
account_offers(accountID, [account_index], [ledger], [callback])
Return the specified account's outstanding offers.
account_tx(options, [callback])
Fetch a list of transactions that applied to this account.
Options:
accountledger_index_minledger_index_maxbinaryfalsecountfalsedescendingfalseoffset0limitforwardfalsefwd_markerrev_marker
wallet_accounts(seed, [callback])
Return a list of accounts for a wallet. Requires trusted remote
account_balance(account, [ledger], [callback])
Get the balance for an account. Returns an Amount object.
account_flags(account, [ledger], [callback])
Return the flags for an account.
owner_count(account, [ledger], [callback])
Return the owner count for an account.
ripple_balance(account, issuer, currency, [ledger], [callback])
Return a request to get a ripple balance
##Orderbook requests
book_offers(options, [callback])
Return the offers for an order book, also called a snapshot
var request = remote.request('book_offers', {
taker_gets: {
'currency':'XRP'
},
taker_pays: {
'currency':'USD',
'issuer': 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
}
});
request.request(function(err, offers) {
//handle offers
});
##Transaction requests
transaction_entry(hash, [ledger_hash], [callback])
Searches a particular ledger for a transaction hash. Default ledger is the open ledger.
Searches ledger history for validated transaction hashes.
sign(secret, tx_json, [callback])
Sign a transaction. Requires trusted remote
Submit a transaction to the network. This command is used internally to submit transactions with a greater degree of reliability. See Submitting a payment to the network for details.
ripple_path_find(src_account, dst_account, dst_amount, src_currencies, [callback])
#Transaction constructors
Use remote.createTransaction('TransactionType', [options]) to construct a transaction. To submit, use transaction.submit([callback]).
Payment
var transaction = remote.createTransaction('Payment', {
account: MY_ADDRESS,
destination: DEST_ADDRESS,
amount: AMOUNT
});
AccountSet
var transaction = remote.createTransaction('AccountSet', {
account: MY_ADDRESS,
set: 'RequireDest',
clear: 'RequireAuth'
});
TrustSet
var transaction = remote.createTransaction('TrustSet', {
account: MY_ADDRESS,
limit: '1/USD/rrrrrrrrrrrrrrrrrrrrBZbvji'
});
OfferCreate
var transaction = remote.createTransaction('OfferCreate', {
account: MY_ADDRESS,
taker_pays: '1',
taker_gets: '1/USD/rrrrrrrrrrrrrrrrrrrrBZbvji'
});
##Transaction events
Transaction objects are EventEmitters. They may emit the following events.
finalTransaction has erred or succeeded. This event indicates that the transaction has finished processing.errorTransaction has erred. This event is a final state.successTransaction succeeded. This event is a final state.presubmitImmediately before transaction is submittedpostsubmitImmediately after transaction is submittedsubmittedTransaction has been submitted to the network. The submission may result in a remote error or success.resubmittedTransaction is beginning resubmission.proposedTransaction has been submitted successfully to the network. The transaction at this point is awaiting validation in a ledger.timeoutTransaction submission timed out. The transaction will be resubmitted.fee_adjustedTransaction 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.abortTransaction has been aborted. Transactions are only aborted by manual calls to#abort.missingFour ledgers have closed without detecting validated transactionlostEight ledgers have closed without detecting validated transaction. Consider the transaction lost and err/finalize.
##Complete payment example
remote.setSecret(MY_ADDRESS, MY_SECRET);
var transaction = remote.createTransaction('Payment', {
account: MY_ADDRESS,
destination: DEST_ADDRESS,
amount: AMOUNT
});
transaction.on('resubmitted', function() {
// initial submission failed, resubmitting
});
transaction.submit(function(err, res) {
// submission has finalized with either an error or success.
// the transaction will not be retried after this point
});
#Amount objects
Coming Soon