Skip to main content

TxBuilder

export interface TxBuilder {
  addCollateral(utxo: TxInput | TxInput[]): TxBuilder
  addDCert(dcert: DCert): TxBuilder
  addOutput(output: TxOutput[]): TxBuilder
  addSigners(hash: PubKeyHash[]): TxBuilder
  apply(fn: (b: TxBuilder) => any): TxBuilder
  attachNativeScript(script: NativeScript): TxBuilder
  attachUplcProgram(program: UplcProgramV2 | UplcProgramV1): TxBuilder
  build(config: TxBuilderFinalConfig): Promise<Tx>
  buildUnsafe(config: TxBuilderFinalConfig): Promise<Tx>
  config: TxBuilderConfig
  delegateUnsafe(
    hash: PubKeyHash | StakingValidatorHash<any>,
    poolId: PubKeyHashLike,
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  delegateWithoutRedeemer(
    hash: PubKeyHash,
    poolId: PubKeyHashLike
  ): TxBuilder
  delegateWithRedeemer(
    hash: StakingValidatorHash<StakingContext<any, TRedeemer>>,
    poolId: PubKeyHashLike,
    redeemer: TRedeemer
  ): TxBuilder
  deregisterUnsafe(
    hash: PubKeyHash | StakingValidatorHash<any>,
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  deregisterWithoutRedeemer(hash: PubKeyHash): TxBuilder
  deregisterWithRedeemer(
    hash: StakingValidatorHash<StakingContext<any, TRedeemer>>,
    redeemer: TRedeemer
  ): TxBuilder
  hasDatum(data: UplcData): boolean
  hasMetadata(): boolean
  hasUplcScripts(): boolean
  inputs: TxInput[]
  mintAssetClassUnsafe(
    assetClass: AssetClass,
    quantity: IntLike,
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  mintAssetClassWithLazyRedeemer(
    assetClass: AssetClass<MintingContext<any, TRedeemer>>,
    quantity: IntLike,
    redeemer: LazyRedeemerData<TRedeemer>
  ): TxBuilder
  mintAssetClassWithoutRedeemer(
    assetClass: AssetClass,
    quantity: IntLike
  ): TxBuilder
  mintAssetClassWithRedeemer(
    assetClass: AssetClass<MintingContext<any, TRedeemer>>,
    quantity: IntLike,
    redeemer: TRedeemer
  ): TxBuilder
  mintedTokens: Assets
  mintPolicyTokensUnsafe(
    policy: MintingPolicyHashLike,
    tokens: [BytesLike, IntLike][],
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  mintPolicyTokensWithoutRedeemer(
    policy: MintingPolicyHash,
    tokens: [BytesLike, IntLike][]
  ): TxBuilder
  mintPolicyTokensWithRedeemer(
    policy: MintingPolicyHash<MintingContext<any, TRedeemer>>,
    tokens: [BytesLike, IntLike][],
    redeemer: TRedeemer
  ): TxBuilder
  mintTokenValueWithoutRedeemer(token: TokenValue): TxBuilder
  mintTokenValueWithRedeemer(
    token: TokenValue<MintingContext<any, TRedeemer>>,
    redeemer: TRedeemer
  ): TxBuilder
  outputs: TxOutput[]
  payUnsafe(
    addr: ShelleyAddressLike,
    value: ValueLike,
    datum: TxOutputDatum
  ): TxBuilder
  payWithDatum(
    address: ShelleyAddress<ValidatorHash<DatumPaymentContext<TDatum>>>,
    value: ValueLike,
    datum: TxOutputDatumCastable<TDatum>
  ): TxBuilder
  payWithoutDatum(
    address: ShelleyAddress<PubKeyHash>,
    value: ValueLike
  ): TxBuilder
  refer(utxos: TxInput<any>[]): TxBuilder
  refInputs: TxInput[]
  reset(): TxBuilder
  setMetadataAttribute(
    key: number,
    value: TxMetadataAttr
  ): TxBuilder
  setMetadataAttributes(attributes: unknown): TxBuilder
  signers: PubKeyHash[]
  spendUnsafe(
    utxos: TxInput<any> | TxInput<any>[],
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  spendWithLazyRedeemer(
    utxos: TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>> | TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>>[],
    redeemer: LazyRedeemerData<TRedeemer>
  ): TxBuilder
  spendWithoutRedeemer(utxos: TxInput<PubKeyHash>[]): TxBuilder
  spendWithRedeemer(
    utxos: TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>> | TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>>[],
    redeemer: TRedeemer
  ): TxBuilder
  sumInputAndMintedAssets(): Assets
  sumOutputAssets(): Assets
  sumOutputValue(): Value
  validFromSlot(slot: IntLike): TxBuilder
  validFromTime(time: TimeLike): TxBuilder
  validToSlot(slot: IntLike): TxBuilder
  validToTime(time: TimeLike): TxBuilder
  withdrawUnsafe(
    addr: StakingAddressLike,
    lovelace: IntLike,
    redeemer: UplcData | LazyRedeemerData<UplcData>
  ): TxBuilder
  withdrawWithLazyRedeemer(
    addr: StakingAddress<StakingValidatorHash<StakingContext<any, TRedeemer>>>,
    lovelace: IntLike,
    redeemer: LazyRedeemerData<TRedeemer>
  ): TxBuilder
  withdrawWithoutRedeemer(
    addr: StakingAddress<PubKeyHash>,
    lovelace: IntLike
  ): TxBuilder
  withdrawWithRedeemer(
    addr: StakingAddress<StakingValidatorHash<StakingContext<any, TRedeemer>>>,
    lovelace: IntLike,
    redeemer: TRedeemer
  ): TxBuilder
}

Properties

addCollateral

txBuilder.addCollateral satisfies (utxo: TxInput | TxInput[]) => TxBuilder

addDCert

txBuilder.addDCert satisfies (dcert: DCert) => TxBuilder

addOutput

Sorts that assets in the output if not already sorted (mutates outputs) (needed by the Flint wallet) Throws an error if any the value entries are non-positive Throws an error if the output doesn't include a datum but is sent to a non-nativescript validator

txBuilder.addOutput satisfies (output: TxOutput[]) => TxBuilder

addSigners

txBuilder.addSigners satisfies (hash: PubKeyHash[]) => TxBuilder

apply

Apply a function to the TxBuilder instance Useful for chaining compositions of TxBuilder mutations The return value of fn is unused

txBuilder.apply satisfies (fn: (b: TxBuilder) => any) => TxBuilder

attachNativeScript

txBuilder.attachNativeScript satisfies (script: NativeScript) => TxBuilder

attachUplcProgram

txBuilder.attachUplcProgram satisfies (program: UplcProgramV2 | UplcProgramV1) => TxBuilder

build

Builds and runs validation logic on the transaction, throwing any validation errors found The resulting transaction may likely still require Tx.addSignature / Tx.addSignatures before it is submitted to the network. The [tx.validate|transaction-validation logic](/docs/sdk/tx-utils/tx.validate|transaction-validation logic) run will throw an error if the transaction is invalid for any reason, including script errors. The config.throwBuildPhaseScriptErrors default (true) will throw script errors during the build phase, but you can set it to false to defer those errors to the validate phase. Use buildUnsafe to get a transaction with possible Tx.hasValidationError set, and no thrown exception.

txBuilder.build satisfies (config: TxBuilderFinalConfig) => Promise<Tx>

buildUnsafe

Builds and runs validation logic on the transaction Always returns a built transaction that has been validation-checked. if the throwBuildPhaseScriptErrors option is true, then any script errors found during transaction-building will be thrown, and the full transaction validation is not run. Caller should check Tx.hasValidationError, which will be false or a validation error string, in case any transaction validations are found. Use TxBuilder.build if you want validation errors to be thrown.

txBuilder.buildUnsafe satisfies (config: TxBuilderFinalConfig) => Promise<Tx>

config

txBuilder.config satisfies TxBuilderConfig

delegateUnsafe

txBuilder.delegateUnsafe satisfies (
  hash: PubKeyHash | StakingValidatorHash<any>,
  poolId: PubKeyHashLike,
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

delegateWithoutRedeemer

txBuilder.delegateWithoutRedeemer satisfies (
  hash: PubKeyHash,
  poolId: PubKeyHashLike
) => TxBuilder

delegateWithRedeemer

txBuilder.delegateWithRedeemer satisfies (
  hash: StakingValidatorHash<StakingContext<any, TRedeemer>>,
  poolId: PubKeyHashLike,
  redeemer: TRedeemer
) => TxBuilder

deregisterUnsafe

txBuilder.deregisterUnsafe satisfies (
  hash: PubKeyHash | StakingValidatorHash<any>,
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

deregisterWithoutRedeemer

txBuilder.deregisterWithoutRedeemer satisfies (hash: PubKeyHash) => TxBuilder

deregisterWithRedeemer

txBuilder.deregisterWithRedeemer satisfies (
  hash: StakingValidatorHash<StakingContext<any, TRedeemer>>,
  redeemer: TRedeemer
) => TxBuilder

hasDatum

txBuilder.hasDatum satisfies (data: UplcData) => boolean

hasMetadata

txBuilder.hasMetadata satisfies () => boolean

hasUplcScripts

txBuilder.hasUplcScripts satisfies () => boolean

inputs

txBuilder.inputs satisfies TxInput[]

mintAssetClassUnsafe

txBuilder.mintAssetClassUnsafe satisfies (
  assetClass: AssetClass,
  quantity: IntLike,
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

mintAssetClassWithLazyRedeemer

Adds minting instructions to the transaction, given a transaction context supporting redeemer transformation

txBuilder.mintAssetClassWithLazyRedeemer satisfies (
  assetClass: AssetClass<MintingContext<any, TRedeemer>>,
  quantity: IntLike,
  redeemer: LazyRedeemerData<TRedeemer>
) => TxBuilder

mintAssetClassWithoutRedeemer

Adds minting instructions to the transaction without a redeemer

txBuilder.mintAssetClassWithoutRedeemer satisfies (
  assetClass: AssetClass,
  quantity: IntLike
) => TxBuilder

mintAssetClassWithRedeemer

Adds minting instructions to the transaction, given a transaction context supporting redeemer transformation

txBuilder.mintAssetClassWithRedeemer satisfies (
  assetClass: AssetClass<MintingContext<any, TRedeemer>>,
  quantity: IntLike,
  redeemer: TRedeemer
) => TxBuilder

mintedTokens

txBuilder.mintedTokens satisfies Assets

mintPolicyTokensUnsafe

Mint a list of tokens associated with a given MintingPolicyHash. Throws an error if the given MintingPolicyHash was already used in a previous call to mint(). The token names can either by a list of bytes or a hexadecimal string. Also throws an error if the redeemer is undefined, and the minting policy isn't a known NativeScript.

txBuilder.mintPolicyTokensUnsafe satisfies (
  policy: MintingPolicyHashLike,
  tokens: [BytesLike, IntLike][],
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

mintPolicyTokensWithoutRedeemer

Adds minting instructions to the transaction without a redeemer

txBuilder.mintPolicyTokensWithoutRedeemer satisfies (
  policy: MintingPolicyHash,
  tokens: [BytesLike, IntLike][]
) => TxBuilder

mintPolicyTokensWithRedeemer

Adds minting instructions to the transaction, given a transaction context supporting redeemer transformation

txBuilder.mintPolicyTokensWithRedeemer satisfies (
  policy: MintingPolicyHash<MintingContext<any, TRedeemer>>,
  tokens: [BytesLike, IntLike][],
  redeemer: TRedeemer
) => TxBuilder

mintTokenValueWithoutRedeemer

Adds minting instructions to the transaction without a redeemer

txBuilder.mintTokenValueWithoutRedeemer satisfies (token: TokenValue) => TxBuilder

mintTokenValueWithRedeemer

Adds minting instructions to the transaction, given a transaction context supporting redeemer transformation

txBuilder.mintTokenValueWithRedeemer satisfies (
  token: TokenValue<MintingContext<any, TRedeemer>>,
  redeemer: TRedeemer
) => TxBuilder

outputs

txBuilder.outputs satisfies TxOutput[]

payUnsafe

txBuilder.payUnsafe satisfies (
  addr: ShelleyAddressLike,
  value: ValueLike,
  datum: TxOutputDatum
) => TxBuilder

payWithDatum

txBuilder.payWithDatum satisfies (
  address: ShelleyAddress<ValidatorHash<DatumPaymentContext<TDatum>>>,
  value: ValueLike,
  datum: TxOutputDatumCastable<TDatum>
) => TxBuilder

payWithoutDatum

txBuilder.payWithoutDatum satisfies (
  address: ShelleyAddress<PubKeyHash>,
  value: ValueLike
) => TxBuilder

refer

Include a reference input

txBuilder.refer satisfies (utxos: TxInput<any>[]) => TxBuilder

refInputs

txBuilder.refInputs satisfies TxInput[]

reset

txBuilder.reset satisfies () => TxBuilder

setMetadataAttribute

txBuilder.setMetadataAttribute satisfies (
  key: number,
  value: TxMetadataAttr
) => TxBuilder

setMetadataAttributes

txBuilder.setMetadataAttributes satisfies (attributes: unknown) => TxBuilder

signers

txBuilder.signers satisfies PubKeyHash[]

spendUnsafe

Add a UTxO instance as an input to the transaction being built. Throws an error if the UTxO is locked at a script address but a redeemer isn't specified (unless the script is a known NativeScript).

txBuilder.spendUnsafe satisfies (
  utxos: TxInput<any> | TxInput<any>[],
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

spendWithLazyRedeemer

txBuilder.spendWithLazyRedeemer satisfies (
  utxos: TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>> | TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>>[],
  redeemer: LazyRedeemerData<TRedeemer>
) => TxBuilder

spendWithoutRedeemer

txBuilder.spendWithoutRedeemer satisfies (utxos: TxInput<PubKeyHash>[]) => TxBuilder

spendWithRedeemer

txBuilder.spendWithRedeemer satisfies (
  utxos: TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>> | TxInput<ValidatorHash<SpendingContext<any, any, any, TRedeemer>>>[],
  redeemer: TRedeemer
) => TxBuilder

sumInputAndMintedAssets

Excludes lovelace

txBuilder.sumInputAndMintedAssets satisfies () => Assets

sumOutputAssets

Excludes lovelace

txBuilder.sumOutputAssets satisfies () => Assets

sumOutputValue

txBuilder.sumOutputValue satisfies () => Value

validFromSlot

Set the start of the valid time range by specifying a slot.

txBuilder.validFromSlot satisfies (slot: IntLike) => TxBuilder

validFromTime

Set the start of the valid time range by specifying a time.

txBuilder.validFromTime satisfies (time: TimeLike) => TxBuilder

validToSlot

Set the end of the valid time range by specifying a slot.

txBuilder.validToSlot satisfies (slot: IntLike) => TxBuilder

validToTime

Set the end of the valid time range by specifying a time.

txBuilder.validToTime satisfies (time: TimeLike) => TxBuilder

withdrawUnsafe

txBuilder.withdrawUnsafe satisfies (
  addr: StakingAddressLike,
  lovelace: IntLike,
  redeemer: UplcData | LazyRedeemerData<UplcData>
) => TxBuilder

withdrawWithLazyRedeemer

txBuilder.withdrawWithLazyRedeemer satisfies (
  addr: StakingAddress<StakingValidatorHash<StakingContext<any, TRedeemer>>>,
  lovelace: IntLike,
  redeemer: LazyRedeemerData<TRedeemer>
) => TxBuilder

withdrawWithoutRedeemer

txBuilder.withdrawWithoutRedeemer satisfies (
  addr: StakingAddress<PubKeyHash>,
  lovelace: IntLike
) => TxBuilder

withdrawWithRedeemer

txBuilder.withdrawWithRedeemer satisfies (
  addr: StakingAddress<StakingValidatorHash<StakingContext<any, TRedeemer>>>,
  lovelace: IntLike,
  redeemer: TRedeemer
) => TxBuilder