ledger

suspend fun ledger(): MidnightLedger

Read the contract's ledger state losslessly.

Returns a MidnightLedger with every top-level ledger field decoded by the contract's own ledger() function via the runtime — NOT by parsing the indexer's flattened JSON cell tree. This is the only way to recover positional information for Vector<N, Uint<8>> (and similar variable-byte) cells when the array contains internal zero elements; the cell hex exposed by MidnightConfig.queryState strips zero-byte elements with no positional markers.

Implementation: fetch the SCALE state hex from the indexer → the cached ledgerEvaluator invokes ledger(chargedState) via QuickJs and marshals each typed getter result back to Kotlin. The result Map is materialized eagerly so subsequent typed accessors are cheap.

Throws

if the indexer query fails.

if the JS evaluation fails or the contract JS doesn't export ledger (likely a contract / client version mismatch).

if this contract was built without an address.