subscribe
Requests push notifications from the server over WebSocket when certain events happen, such as a new validated ledger, transactions affecting an account, or changes to an order book. Available over WebSocket only.
This method will use 20 Compute Units and each notification pushed on the subscription will use 10 Compute Units regardless of size.
Reference: Here
Parameters
streams(array, optional) Streams to subscribe to. Each member must be the string name of a stream. Supported on this endpoint:ledgersends aledgerClosedmessage whenever the consensus process declares a new validated ledger.transactionssends atransactionmessage whenever a transaction is included in a validated ledger.transactions_proposedsends atransactionmessage for validated transactions and for some proposed transactions that have not yet been validated and may never be.validationssends avalidationReceivedmessage whenever the server receives a validation message, whether or not it trusts the validator.manifestssends amanifestReceivedmessage whenever the server receives an update to a validator's ephemeral signing key.book_changessends abookChangesmessage with order book changes whenever a new ledger is validated.
accounts(array, optional) Addresses of accounts to monitor for validated transactions. The server sends atransactionmessage whenever a transaction affects at least one of these accounts.accounts_proposed(array, optional) Likeaccounts, but also includes transactions that are not yet finalized.books(array, optional) Order books to monitor. Each member is an object withtaker_getsandtaker_pays(currency objects without amounts) and the optional fieldsboth(return both sides of the book),snapshot(send the current state of the book once when you subscribe),taker(perspective account) anddomain(permissioned DEX).
The peer_status, consensus and server streams are not available on this endpoint; requesting one of them returns an error. The admin-only url callback fields are not supported.
Returns
result(object) Depends on what was subscribed. For theledgerstream it carries the current ledger state:fee_base,ledger_hash,ledger_index,ledger_time,network_id,reserve_base,reserve_incandvalidated_ledgers. Subscribing tobookswithsnapshot: truereturns the current offers inresult.offers(orresult.asksandresult.bidswhenbothistrue). For every other stream and foraccounts,resultis an empty object.
Each subsequent push message is a JSON object with a type field that identifies the stream. A ledger stream message looks like this:
ledgerClosed(ledger stream):fee_base,ledger_hash,ledger_index,ledger_time,network_id,reserve_base,reserve_inc,txn_countandvalidated_ledgers.transaction(transactions, transactions_proposed, accounts, accounts_proposed and books):engine_result,engine_result_code,engine_result_message,ledger_hash,ledger_index,meta,tx_json(the transaction),validatedand, for proposed transactions,status: "proposed".validationReceived(validations stream):ledger_hash,ledger_index,validation_public_key,master_key,signing_time,signature,full,flags,cookieand, when present,amendments,base_fee,reserve_baseandreserve_inc.manifestReceived(manifests stream):master_key,signing_key,seq,signatureandmaster_signature.bookChanges(book_changes stream): the same fields as thebook_changesmethod (ledger_hash,ledger_index,ledger_timeand achangesarray).
The native XRPL request shape shown above puts the parameters at the top level next to command. The JSON-RPC shaped request {"jsonrpc":"2.0","id":1,"method":"subscribe","params":[{"streams":["ledger"]}]} is also accepted on the same WebSocket connection. To watch specific accounts or an order book, add accounts or books to the same request, for example {"id":2,"command":"subscribe","accounts":["rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De"]}. Subscriptions end when you send unsubscribe or close the connection.
Last updated
Was this helpful?