Ledger

The ledger namespace is used for preparing, signing, and executing transactions and other Ledger API operations.

Availability

The ledger namespace is always available as part of the basic SDK interface. It’s initialized automatically when you create an SDK instance and doesn’t require additional configuration via extend().

import { localNetStaticConfig, SDK } from '@canton-network/wallet-sdk'

export default async function () {
    const sdk = await SDK.create({
        auth: global.TOKEN_PROVIDER_CONFIG_DEFAULT,
        ledgerClientUrl: localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL,
        amulet: global.AMULET_NAMESPACE_CONFIG,
    })

    const partyId = EXISTING_PARTY_1
    const privateKey = EXISTING_PARTY_1_KEYS.privateKey

    const [commands, disclosedContracts] = await sdk.amulet.tap(partyId, '200')

    // ledger namespace is immediately available
    await sdk.ledger
        .prepare({ partyId, commands, disclosedContracts })
        .sign(privateKey)
        .execute({ partyId })
}

Key changes from v0 to v1

v0 used the userLedger or adminLedger controller with implicit party context set via sdk.setPartyId().

v1 uses the ledger namespace where you:

  • Pass partyId explicitly to each operation

  • Have an explicit lifecycle with prepare/sign/execute chain instead of a single method

  • Access operations through logical groupings (external, internal, dar, and acs)

Prepare, signing, and executing transactions

Previously, a single method would handle everything.

Each step in lifecycle is clearer, workflowIds are generated automatically and there is better typesafety at each step.

The below example demonstrates how offline signing works.

Active Contract Set (ACS) queries

No need to manually enter get the ledger end for the offset and there is direct extraction of the activeContracts. However, we still have an acs.readRaw method for unfiltered results.

DAR management

Migration reference

Ledger namespace migration

v0 method

v1 method

sdk.userLedger.prepareSignExecuteAndWaitFor

sdk.ledger.prepare({partyId, commands, disclosedContracts}).sign(privateKey).execute(partyId)

sdk.userLedger.activeContracts

sdk.ledger.acs.read

sdk.adminLedger.uploadDar

sdk.ledger.dar.upload

sdk.userLedger.isPackageUploaded

sdk.ledger.dar.check

See also