Ledger exposes several records for different questions. Read an account for its current volumes, read a transaction for an accepted movement, use logs for committed changes, and use the audit trail to investigate both accepted and rejected proposals (a proposal is a write batch submitted to Ledger).
Ledger's base URL depends on how it is deployed. A Ledger server you run yourself answers at the root of its host. Behind a Formance Stack, requests pass through the Stack Gateway, which serves Ledger under /api/ledger. If you reach Ledger through your Stack's domain you are going through the Gateway; if you started the server yourself, you are not.
Run the commands for your deployment in a shell, and keep that same shell for the rest of the guide. set -eo pipefail stops the shell at the first failing command instead of carrying on with an empty value:
The token needs ledger:read and ledger:write. ledger is the default auth service name. If your deployment uses another service name, replace ledger with your configured name.
These reads target a ledger that already holds the records you want to inspect:
Grant each application only the scopes needed by the routes it calls. See Authentication and Authorization.
| HTTP read | Required scope |
|---|---|
| Accounts and volumes | ledger:AccountRead |
| Transactions | ledger:TransactionRead |
| Per-ledger logs and statistics | ledger:LedgerRead |
| Bucket-wide audit entries | ledger:AuditRead |
The gRPC ListLogs method used by ledgerctl logs list requires the same ledger:LedgerRead scope as the HTTP log route.
Choose the record#
| Question | Record to read | Data boundary |
|---|---|---|
| What does this account hold now? | Account | One ledger |
| Which postings and metadata were committed? | Transaction | One ledger |
| Which successful mutations changed this ledger? | Ledger log | One ledger |
| Why was a proposal accepted or rejected? | Audit entry | The whole bucket |
| How many transactions, postings, logs, and related records exist? | Ledger statistics | One ledger |
Logs and audit entries are related, but they are not interchangeable. Each fresh proposal that reaches Ledger's state machine produces one audit entry, whether it succeeds or fails. A successful proposal can produce several logs or none. An idempotent replay produces neither another log nor another audit entry, and a request rejected before application is not part of this audit trail.
Read an account#
Retrieve one account by its full address:
The response contains the address, typed metadata, and volumes. Volumes are separated by asset and color. Add ?collapseColors=true only when the caller intentionally wants one total per asset and does not need the color boundary.
List accounts when the application does not know the complete address:
Account lists are ordered alphabetically. See Filter and Paginate Results before using a list route for an unbounded export.
Read a transaction#
Retrieve a transaction by its numeric ID:
The response contains the committed transaction.
List transactions to search by reference, account, metadata, or date:
The default transaction order is newest first. Pass reverse=true for oldest first. Reference and date filters require their corresponding indexes to be ready. The structured reference match is exact. The textual filter grammar does not expose a reference condition.
Trace a successful transaction#
Use this sequence when an application needs to explain what happened to a successful write. It correlates a business reference with the transaction, the global log sequence, and the bucket-wide audit entry, in three hops:
referenceto the transactionid, from the transaction list;- transaction
idto the globalsequence, from the ledger logs, atpayload.apply.log.data.transaction.idon aNEW_TRANSACTIONlog; - global
sequenceto the audit entry, withfilter=log_seq == <sequence>.
Start with the business reference and idempotency key recorded by the caller, then wait for one exact transaction. A filtered HTTP list can briefly lag behind a fresh write, so an empty result is not yet a negative result:
The loop waits for a positive match and reports an unknown correlation after its deadline. pageSize=2 is intentional: references are unique, and a second exact match would reveal a violated assumption instead of silently choosing one.
Next, traverse the ledger logs until the created-transaction payload contains that transaction ID. The HTTP log list can also briefly lag behind a fresh write. Follow each page's next token and, at the end of the visible logs, poll from the last log returned until the target arrives or the wait expires. The page token is keyed by the ledger-local log ID, while LOG_SEQUENCE comes from the enclosing global log:
Resuming after the last log returned is safe because ledger logs become visible in ledger-local ID order, without gaps. The hand-built token is the base64url form, without padding, of {"key": "<log ID>"}, the same token a next link would carry. A page without next means “no more logs are visible yet,” not “the creation log does not exist.” The loop waits there for more logs and never turns the timeout into an absence claim.
Finally, use the global log sequence to locate and retrieve the audit entry. The HTTP audit filter reads an asynchronous secondary index, so wait for that index instead of treating an empty first response as proof that the audit entry is missing:
The loop waits for a positive match and fails with an unknown result after its deadline; it never turns temporary audit-index lag into a missing-record conclusion. The first jq prints true only when all three records agree on the ledger, global log sequence, and expected idempotency key. The second prints the correlation summary. The audit entry's sequence is its own identifier; it is not the global log sequence. The caller snapshot is the identity and permissions Ledger recorded when it admitted the proposal.
The audit API cannot filter by idempotency key. If the key is the only available clue, narrow an audit list by ledger, caller, time, and outcome, then retrieve candidate details and compare .data.idempotency.key in the client.
Investigate failed proposals#
A failed proposal has no transaction or committed log to follow. Query the audit trail directly by outcome, ledger, caller, proposal, or time. A date filter on the ledger log route additionally requires the opt-in log-date index; see Create and Manage Indexes.
For a recently failed proposal, use its idempotency key as the final correlation check. The filter narrows the candidate set, but the HTTP audit index can lag, so retry for a bounded period and retrieve each compact candidate before deciding:
An audit item has logSequence: 0 when its order produced no log. If the candidate volume can exceed 100 entries during the wait window, narrow the filter further with the known caller, proposal, or time range, or page through all candidates. A timeout is an observability result, not proof that Ledger never admitted the failed proposal.
Audit routes are bucket-scoped because one proposal can contain orders for more than one ledger. Select a ledger with the audit filter; do not add a ledger name to the URL.
Use ledgerctl over gRPC#
ledgerctl exposes the gRPC read surface and can print machine-readable output:
Use gRPC or ledgerctl when the read must wait for a minimum log sequence or target a query checkpoint. HTTP reads use the default linearizable consistency for each request, but the direct list routes do not expose those additional controls. A linearizable barrier confirms committed cluster state; it does not by itself make an asynchronous secondary index current. See Choose Read Consistency and Use Checkpoints.
Verify the result#
- A direct lookup returns
404when the record does not exist in the selected ledger or bucket. - A list returning no rows is not proof that a recent write failed. First check the selected ledger, filter, index readiness, and read-consistency choice.
- A transaction proves that Ledger committed the movement. An audit failure explains why Ledger rejected a proposal before it became a transaction.
- Statistics are not an instant write receipt.
transactionCountandlogCountadvance synchronously, while the seven usage counters can briefly lag on the replica that serves the request.
See Verify Ledger Integrity for an integrity assessment of stored state; query results are not an integrity proof.
Continue with Filter and Paginate Results when one read must return a subset larger than a single response.