Mesh LogoMesh

Options

Every option of TxBuilder, build() and plan(), with what it does and its default.

Overview

Options live in three places: the builder (new TxBuilder({...}), set once), a build (builder.build(parts, {...}), set per call) and a plan (builder.plan(steps, {...}), which takes the build options too). Use this page to find a name and its default. The calls of a BuiltTx and of a plan (sign, submit, awaitInclusion, run, add, replan, resume) refuse an unknown member with INVALID_OPTION. The options of the builder, build() and plan() are checked by type only, so rely on TypeScript to catch a misspelled name.

Examples use the names of Transaction Basics: provider, wallet, recipient and builder.

Builder Options

Give these to new TxBuilder({...}). Only network is required, and a builder with a network alone is made. With neither a provider nor params, it reads and signs only: build(), plan(), chain() and a plan's add and replan throw MISSING_PARAMETER at the call, since there are no built-in parameter values. See A Builder with a Network Alone.

OptionWhat it doesDefault
network"mainnet", "preprod", "preview" or customNetwork(...) for a devnet. Every address, wallet and provider is checked against itrequired
providerReads the chain: outputs, parameters, cost models, the payer's UTxOs. Plans also read the tipnone
paramsProtocol parameters (a Protocol), used instead of reading themread from the provider; with no provider either, MISSING_PARAMETER at the call that needs them
costModelsCost models by Plutus language, V1 first (number[][]), used instead of reading themread from the provider
depositsdrepDeposit and govActionDeposit, which Protocol does not carrynone
submitterSends transactions in place of the providerthe provider
evaluatorWorks out execution units. null turns it off, and then every redeemer needs its own units. provider evaluates through the providera local evaluator
serializerAn IMeshTxSerializer with serializeTxPrototypethe built-in encoder
planDefaultsDefaults of plans: ttlMs, expiryMarginMs, confirmations, pollMs, resendMs. See Plan Optionsbuilt-in values
storeA TxPlanStore that records every plan, so it can be resumed by its idnone: plans are not recorded

Build Options

Give these to builder.build(parts, {...}).

Payer and Inputs

OptionWhat it doesDefault
payerWho pays and gets the change: a wallet, an address, or { changeAddress, utxos }none: MISSING_PAYER
canSelect(utxo) => boolean: which of the payer's UTxOs may be selected. Script-locked UTxOs and UTxOs the parts read are never selectedall selectable UTxOs
coinSelection(need, candidates) => outRefs: replaces the built-in selection for this buildthe built-in selection
sendAllToSpends every selectable UTxO and sends what is left to this addressnone
knownUtxosOutputs that parts name by out ref and the provider may not know yetnone
afterTransactions built before and not yet seen by the provider (a BuiltTx, a TxPlan or a list). Their inputs are not selected again, and their outputs can be spentnone

Fee, Collateral and Keys

OptionWhat it doesDefault
feeA fee in lovelace (bigint) that goes into the body as given. Too low is FEE_TOO_LOW; above the minimum is the warning FEE_ABOVE_MINIMUMworked out
topUpCollateraltrue: collateral inputs you give that do not cover the collateral get more from the payer. false: they are used as given, and a shortfall is INSUFFICIENT_COLLATERALtrue
collateralReturntrue: the transaction states its total collateral and returns the rest. false: collateral inputs only, with all of their lovelace at stake (COLLATERAL_FORFEITED)true
extraKeyWitnessesA number: key witnesses expected beyond those the parts call fornone
registeredPoolsOperator key hashes of pools that are already registerednone

Control

OptionWhat it doesDefault
signalAn AbortSignal. Aborting it ends the build with ABORTEDnone
traceReceives the steps of the build (payer, fetched, round, evaluated), for diagnosticsnone

Set Builder and Build Options

Builder options go in the constructor, and build options in the second argument of build(). A build option applies to that call only.

import { output, TxBuilder } from "@meshsdk/core";

// Builder options: set once
const builder = new TxBuilder({
  network: "preprod",
  provider,
  planDefaults: { confirmations: 10 },
});

// Build options: set per build
const built = await builder.build(
  output({ address: recipient, value: { lovelace: 5_000_000n } }),
  {
    payer: wallet,
    canSelect: (utxo) => utxo.value.lovelace > 3_000_000n, // skip small UTxOs
    signal: AbortSignal.timeout(30_000), // give up after 30 seconds
  },
);

Plan Options

builder.plan(steps, {...}) takes the build options and these. With named steps, give sendAllTo and fee inside the step. The three deadlines are worked out once, when the plan is made, and recorded in it.

OptionWhat it doesDefault
idYour id for the plan, shown as plan.id. Required on a builder with a storenone
consolidatetrue: when a step's inputs do not fit one transaction, the plan adds consolidation steps before it. { maxSteps } limits them (1 to 31). false: that step is TX_TOO_LARGEtrue, up to 4 steps
ttlMsHow long a step is valid when its parts set no validity({ until }), and the time left to sign it600_000 (10 minutes)
expiryMarginMsThe wait after a step's end of validity before the plan calls it expired600_000 (10 minutes)
confirmationsBlocks on top of a step's block before it is final30

planDefaults of the builder gives these three their defaults, and adds pollMs (5_000, the pause between two looks at the chain) and resendMs (120_000, how often the same bytes of a sent step go again while it is not found).

plan.run({...}) takes options of its own. They are never recorded in the plan.

OptionWhat it doesDefault
signersWho signs a step that still needs signaturesthe payer
submitterWho sends. A wallet sends only when it is given as a submitter, here or to the builder. The payer never sends by itselfthe builder's submitter, else the provider
waitForHow far run() goes: "sent", "included" or "final""included"
timeoutMsHow long run() waits for a block, then CONFIRM_TIMEOUT120_000; for "final", confirmations × 30_000 + 120_000
pollMsThe pause between two looks at the chainplanDefaults, else 5_000
signalAborts the call with ABORTEDnone
import { output } from "@meshsdk/core";

const plan = await builder.plan(
  { pay: output({ address: recipient, value: { lovelace: 5_000_000n } }) },
  { payer: wallet, id: "payment-1", ttlMs: 20 * 60_000 }, // 20 minutes to sign
);
await plan.run({ waitFor: "final", timeoutMs: 30 * 60_000 });

built.sign({ signers, partial }), built.submit({ submitter }) and built.awaitInclusion({ timeoutMs, pollMs }) take options too: see Signing and Submitting.

On this page