sdk/builders/RedeemerBuilder.ts
RedeemerBuilder overview
Deferred redeemer construction for dynamic index resolution.
Cardano redeemers must reference inputs/policies by their sorted index in the final transaction. But coin selection may add new inputs, changing all indices. This creates a chicken-and-egg problem: you need indices to build redeemers, but indices aren't known until the transaction is finalized.
The solution is three modes:
- Static: When you know the redeemer value upfront (no index needed)
- Self: When redeemer depends on THIS input's final index
- Batch: When redeemer depends on MULTIPLE inputs' final indices
Added in v2.0.0
Table of contents
types
BatchRedeemerBuilder (interface)
Batch redeemer builder for multi-input coordination.
When multiple UTxOs need to share information about each other's indices,
use batch mode. The all function receives all specified inputs with their
resolved indices.
Signature
export interface BatchRedeemerBuilder {
/** Function invoked with all inputs' resolved indices. */
readonly all: BatchRedeemerFn
/** Which UTxOs to include in the batch. */
readonly inputs: ReadonlyArray<UTxO.UTxO>
}Added in v2.0.0
BatchRedeemerFn (type alias)
Batch-mode function: constructs a single redeemer from multiple inputs.
Called once with all indexed inputs, returns one redeemer shared by all. Use when multiple inputs need coordinated redeemer values.
Signature
export type BatchRedeemerFn = (inputs: ReadonlyArray<IndexedInput>) => Data.DataAdded in v2.0.0
IndexedInput (interface)
An input with its resolved transaction index.
Provided to redeemer functions after coin selection completes. Contains both the final sorted index and the original UTxO for reference.
Signature
export interface IndexedInput {
/** The final 0-based index of this input in the sorted transaction inputs. */
readonly index: number
/** The original UTxO being spent. */
readonly utxo: UTxO.UTxO
}Added in v2.0.0
RedeemerArg (type alias)
Redeemer argument for collectFrom and mint operations.
Supports three modes:
- Static (
Data): Direct redeemer value, no deferred computation - Self (
SelfRedeemerFn): Per-input function, receives{ index, utxo } - Batch (
BatchRedeemerBuilder): Multi-input function, receives array
The appropriate mode is auto-detected at runtime:
- Function → Self mode
- Object with
allproperty → Batch mode - Otherwise → Static mode
Signature
export type RedeemerArg = Data.Data | SelfRedeemerFn | BatchRedeemerBuilderAdded in v2.0.0
SelfRedeemerFn (type alias)
Self-mode function: constructs a redeemer for a single script input.
Called once per script-locked UTxO with its resolved index. The same function is invoked for each script UTxO in the collection.
Signature
export type SelfRedeemerFn = (input: IndexedInput) => Data.DataAdded in v2.0.0
utils
isBatchBuilder
Signature
export declare const isBatchBuilder: (arg: RedeemerArg) => arg is BatchRedeemerBuilderAdded in v2.0.0 @category guards
isSelfFn
Signature
export declare const isSelfFn: (arg: RedeemerArg) => arg is SelfRedeemerFnAdded in v2.0.0 @category guards
isStaticData
Signature
export declare const isStaticData: (arg: RedeemerArg) => arg is Data.DataAdded in v2.0.0 @category guards