Documentation
Enclave SDK
Ledger

Ledger

Klave provide access to a Ledger database for your application. The Klave ledger database is tamper-proof NoSQL key-value data-store. This key value store allows Klave developers to persist non-relational data across application invocation in a secure and tamper-proof way. To learn more about the ledger charateristics, check out Ledger and Integrity.

Using the Ledger from Applications

The Klave SDK exposes an interface to interact with the ledger.

The set of operations is the following one:

ClassOperationParametersReturnsBehavior
LedgergetTablenameTableReturn the ledger table with the specified name. If no table exists from the name provided, then a new table with this name will be automatically created and returned.
TablegetkeyvalueGet the string value associated with the specified key from the specified Table as string.
Tablesetkey, value-Set the value as string associated with the specified key in the specified Table, overwriting any existing value.
Tableunsetkey-Delete the tuple with the specified key from the specified Table.

In AssemblyScipt, the ledger can be accessed through the Ledger keyword. For example:

import { Ledger } from '@klave/sdk';
 
@serializable
export class StoreInput {
    key!: string;
    value!: string;
}
 
/**
 * @transaction
 */
export function storeInLedger(input: StoreInput): void {
    Ledger.getTable("MY_TABLE").set(input.key, input.value);
}
 
/**
 * @query
 */
export function retrieveFromLedger(key: string): void {
    let value = Ledger.getTable("MY_TABLE").get(key);
}