Skip to content

Api Events

callchain edited this page Apr 2, 2018 · 2 revisions

API Events

ledger

This event is emitted whenever a new ledger version is validated on the connected server.

Return Value

Name Type Description
baseFeeCALL value Base fee, in CALL.
ledgerHash string Unique hash of the ledger that was closed, as hex.
ledgerTimestamp date-time string The time at which this ledger closed.
reserveBaseCALL value The minimum reserve, in CALL, that is required for an account.
reserveIncrementCALL value The increase in account reserve that is added for each item the account owns, such as offers or trust lines.
transactionCount integer Number of new transactions included in this ledger.
ledgerVersion integer Ledger version of the ledger that closed.
validatedLedgerVersions string Range of ledgers that the server has available. This may be discontiguous.

Example

api.on('ledger', ledger => {
  console.log(JSON.stringify(ledger, null, 2));
});
{
  "baseFeeCALL": "0.00001",
  "ledgerVersion": 14804627,
  "ledgerHash": "9141FA171F2C0CE63E609466AF728FF66C12F7ACD4B4B50B0947A7F3409D593A",
  "ledgerTimestamp": "2015-07-23T05:50:40.000Z",
  "reserveBaseCALL": "20",
  "reserveIncrementCALL": "5",
  "transactionCount": 19,
  "validatedLedgerVersions": "13983423-14804627"
}

error

This event is emitted when there is an error on the connection to the server that cannot be associated to a specific request.

Return Value

The first parameter is a string indicating the error type:

  • badMessage - calld returned a malformed message
  • websocket - the websocket library emitted an error
  • one of the error codes found in the calld Universal Errors.

The second parameter is a message explaining the error.

The third parameter is:

  • the message that caused the error for badMessage
  • the error object emitted for websocket
  • the parsed response for calld errors

Example

api.on('error', (errorCode, errorMessage, data) => {
  console.log(errorCode + ': ' + errorMessage);
});
tooBusy: The server is too busy to help you now.

connected

This event is emitted after connection successfully opened.

Example

api.on('connected', () => {
  console.log('Connection is open now.');
});

disconnected

This event is emitted when connection is closed.

Return Value

The only parameter is a number containing the close code send by the server.

Example

api.on('disconnected', (code) => {
  if (code !== 1000) {
    console.log('Connection is closed due to error.');
  } else {
    console.log('Connection is closed normally.');
  }
});
Clone this wiki locally