Skip to content

feat(transaction): build, sign and send transactions from parts with TxBuilder - #873

Open
lisicky wants to merge 320 commits into
feat/tx-emulatorfrom
feat/tx-builder
Open

lisicky wants to merge 320 commits into
feat/tx-emulatorfrom
feat/tx-builder

Conversation

@lisicky

@lisicky lisicky commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Stacked on #858 (which is stacked on #864): merge those first.

What

A new transaction builder in @meshsdk/transaction, TxBuilder. A transaction is a list of parts — output(...), spend.plutus(...), mint.native(...), certificate.stakeDelegation(...), ... — given to the builder with a payer; the builder selects inputs, adds change, works out the fee, collateral and execution units, and returns the transaction as an object that signs, submits and waits for itself. Several transactions that depend on each other are built at once as a plan, sent in order and followed to the chain. The fluent MeshTxBuilder keeps working, deprecated, on top of the new builder.

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

const builder = new TxBuilder({ network: "preprod", provider });
const built = await builder.build(
  output({ address: recipient, value: { lovelace: 5_000_000n } }),
  { payer: wallet },
);
await built.sign();
await built.submit();

Contents

Building

  • Parts for every piece of a Conway transaction: inputs (key, native and Plutus script spends, reference inputs, collateral), outputs, mint, withdrawals, every certificate, votes, proposals, validity, metadata and message, required signers, donations.
  • A payer is a wallet, an address, or a snapshot { changeAddress, utxos }; UTxOs are taken in any of three forms (the builder's Utxo, a Mesh UTxO, the CBOR of a transaction unspent output).
  • The builder evaluates the final transaction locally by default, puts up collateral and a collateral return, and orders every item by the ledger's rules. Offline builds take params and costModels; a builder with a network alone reads and signs.
  • Errors are typed (TxBuildError, TxPartError, TxPlanError) with codes and details; TxError.is(error, code) checks them.

One transaction: BuiltTx

  • build() returns a BuiltTx: the data of the build, sign() (a wallet, a private key through keySigner, or a signer of transaction hashes), addWitnesses(), submit(), awaitInclusion(), and JSON with builder.restore().
  • builder.fromCbor(tx, { knownUtxos }) makes the same object of a transaction built elsewhere, to read its outputs, fee, collateral and missing signers before signing; { blind: true } signs without reading its inputs. requiredSigners(tx, spent) lists who must sign.
  • A transaction is never rebuilt to retry: the same object sends the same bytes.

Several transactions: TxPlan

  • builder.plan(steps, { payer }) builds a group of transactions at once; run() signs, sends and waits for each in order, with statuses from built to final, deadlines, stop(), replan() and plan.add().
  • A step that needs more inputs than one transaction holds gets consolidation steps before it.
  • Plans can be kept in a store and resumed after a restart; a repeated call never pays twice.

Reading CBOR

  • Transactions, UTxOs and reference scripts given as CBOR are read with the SDK's CborReader, bounded in size, depth and work; reference scripts are not decoded. CBOR the application gives (data, datums, redeemers, native scripts) is kept byte for byte unless it breaks the transaction's structure.
  • A native script whose keys cannot be read is refused where the signers are listed (NATIVE_SCRIPT_UNREAD).

Other packages

  • @meshsdk/core-cst: reading a TransactionPrototype from CBOR, adding witnesses to a transaction in its own form, @cardano-sdk/core 0.47.1.
  • @meshsdk/wallet: wallets write witnesses in the transaction's form.
  • @meshsdk/common: types the builder takes.

Editor support

  • Every part takes a named, exported parameter type with each field described, so hover and completion show the descriptions.

Docs

  • packages/mesh-transaction/README.md: the guide, with examples type-checked in CI.
  • docs/design/tx-builder.md: the design.

MeshTxBuilder

  • Kept, @deprecated, running on TxBuilder. Where it used to return a transaction the ledger refuses, it now throws the new builder's error; the README lists every difference and the members removed.

Validation

Run locally on the head of this branch, as CI runs them:

  • turbo build:mesh, build:docs, build:apps, build:scripts, lint
  • all package tests: 6 333 pass, 5 209 of them in @meshsdk/transaction
  • tsc and the typecheck of every package's tests; the README's TypeScript examples compile
  • test:package of @meshsdk/core-cst and @meshsdk/scalus-emulator, and test:scalus-packages
  • the tests that submit to the emulator run on both of its validators; the plan race test passes with 24 seeds on each

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant