Skip to content

Reference

selectLockedAmuletForAmount

Pure helper that picks the smallest qualifying locked Amulet covering a spend target with optional exclusivity and expiration filters.

selectLockedAmuletForAmount filters LockedAmulet structs in memory:

  • effectiveAmountamountNeeded
  • Optional requireExclusiveHolder (default true) rejects multi-holder locks.
  • Optional rejectExpiredLocks (default true) rejects locks whose lockExpiresAt is in the past relative to nowMs.

Candidates sort ascending by effectiveAmount so the cheapest sufficient contract is chosen (avoids overspending).

Setup

import { selectLockedAmuletForAmount, getLockedAmuletsForParty } from '@fairmint/canton-node-sdk';

const canton = new Canton({
  network: 'NETWORK_NAME',
  partyId: 'PARTY_ID',
});

Minimal example

const locked = await getLockedAmuletsForParty(canton.validator, 'OWNER_PARTY_ID');
const choice = selectLockedAmuletForAmount(locked, 25.5, {
  requireExclusiveHolder: true,
  rejectExpiredLocks: true,
});

console.log(choice?.contractId ?? 'no match');

Parameters

  • amulets — Array of LockedAmulet rows (for example from getLockedAmuletsForParty).
  • amountNeeded — Positive finite number representing the Amulet quantity to cover.
  • options (optional)LockedAmuletSelectionOptions: requireExclusiveHolder, rejectExpiredLocks, nowMs.

Returns

LockedAmulet | nullnull when no contract satisfies constraints.

Errors

Throws ValidationError when amountNeeded is not finite or <= 0.

Auth and party

Pure function — no network. Apply only after fetching candidate rows with correct party scope.

See also

Source

src/utils/amulet/select-funding-amulets.ts