Skip to content

feat(tx-construction): expose tx-builder utils and add fluent minting#1686

Merged
rhyslbw merged 3 commits into
masterfrom
feat/export-tx-builder-utils
Jun 18, 2026
Merged

feat(tx-construction): expose tx-builder utils and add fluent minting#1686
rhyslbw merged 3 commits into
masterfrom
feat/export-tx-builder-utils

Conversation

@rhyslbw

@rhyslbw rhyslbw commented Jun 17, 2026

Copy link
Copy Markdown
Member

Closes gaps in @cardano-sdk/tx-construction that forced consumers (e.g. Lace's full-domain Cardano transaction builder) to reimplement SDK internals or drop to lower-level APIs.

1. Export tx-builder utils

buildRedeemers, buildWitness and computeCollateral are defined in tx-builder/utils.ts but the barrel never re-exported ./utils, so they were absent from the public API. Fixed with export * from './utils' (pure addition, no collisions).

2. Fluent minting on the transaction builder

Add TxBuilder.addMint({ policy, assets, redeemer }). The policy script is attached to the witness set, the asset quantities are added to the body, and for Plutus policies the redeemer is included and its execution units evaluated during build(). Previously GenericTxBuilder had no minting supportmint was never forwarded to initializeTx.

3. Canonical redeemer indexing (review follow-up)

Redeemer pointers must reference an item's position in the canonically-sorted transaction-body collection, not insertion order. RedeemersByType now keys redeemers by on-chain identifier (mint → PolicyId, withdrawal → RewardAccount, vote → Voter), and computeMinimumCost derives each index from the body:

  • mint: rank of the policy id in the sorted minting policies.
  • withdrawal: rank among script-credential reward accounts sorted by hash; key-hash withdrawals carry no redeemer and don't shift the index (node quirk).
  • vote: position in the canonically-sorted voters (voter group, then script-before-keyhash credential, then hash).
  • certificate / propose: caller-provided index (item position in body order).

The @cardano-sdk/web-extension remote-api property map gains the new addMint method.

Tests

  • Unit (TxBuilderPlutusScripts.test.ts): plutus mint with redeemer, burn (negative quantity), native-script mint without a redeemer, and multi-policy redeemer indexing.
  • Canonical-index vector (selectionConstraints.test.ts): withdrawal indices computed among script reward accounts by hash, with a key-hash withdrawal interleaved and the body out of canonical order. Full @cardano-sdk/tx-construction suite green (221).
  • E2E (PersonalWallet/mint.test.ts): the mint scenario now builds through createTxBuilder().addMint(...).build().sign() instead of initializeTx, validated on-chain by the e2e workflow (wallet_epoch_0, runs on PR).

Open

Vote redeemer ordering is derived from the ledger Voter Ord (the cardano-c reference for votes was past the readable excerpt) and lacks a dedicated vector — flagged in-thread for confirmation against the reviewer's vote vectors. Withdrawal-with-redeemer is otherwise reachable via the documented customize hook; a first-class "build unsigned tx for external signers" path remains a follow-up.

🤖 Generated with Claude Code

buildRedeemers, buildWitness and computeCollateral are defined in
tx-builder/utils.ts but the tx-builder barrel never re-exported them, so
they were absent from the package's public API. Consumers assembling Plutus
transactions manually (mint / script-spend / withdrawal redeemers,
collateral) had to reimplement buildRedeemers and could not use
computeCollateral. Re-export ./utils from the barrel to expose them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rhyslbw rhyslbw marked this pull request as draft June 17, 2026 11:32
@rhyslbw rhyslbw changed the title feat(tx-construction): export tx-builder utils for manual tx assembly feat(tx-construction): expose tx-builder utils and add fluent minting Jun 17, 2026
@rhyslbw rhyslbw force-pushed the feat/export-tx-builder-utils branch from b92758b to 6a6f296 Compare June 17, 2026 12:29
@rhyslbw rhyslbw requested a review from AngelCastilloB June 17, 2026 12:51
@rhyslbw rhyslbw marked this pull request as ready for review June 17, 2026 12:51
@rhyslbw rhyslbw marked this pull request as draft June 17, 2026 13:55
@rhyslbw rhyslbw force-pushed the feat/export-tx-builder-utils branch 2 times, most recently from aa81090 to 3737871 Compare June 17, 2026 14:03
Comment thread packages/tx-construction/src/input-selection/selectionConstraints.ts Outdated
@rhyslbw rhyslbw force-pushed the feat/export-tx-builder-utils branch from 3f50970 to fca0493 Compare June 17, 2026 15:04
@rhyslbw rhyslbw marked this pull request as ready for review June 17, 2026 15:11
Comment thread packages/tx-construction/test/tx-builder/TxBuilderPlutusScripts.test.ts Outdated
AngelCastilloB
AngelCastilloB previously approved these changes Jun 17, 2026

@AngelCastilloB AngelCastilloB left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @rhyslbw

AngelCastilloB
AngelCastilloB previously approved these changes Jun 17, 2026
Add `TxBuilder.addMint({ policy, assets, redeemer })` so consumers can mint or
burn assets under a policy without dropping to the lower-level `initializeTx`.
The policy script is attached to the witness set, the asset quantities are added
to the body, and (for Plutus policies) the redeemer is included and its execution
units evaluated during `build()`. Previously `GenericTxBuilder` had no minting
support — `mint` was never forwarded to `initializeTx`.

This also fixes redeemer index reconciliation for non-spend purposes: builder
redeemers are stamped with a sentinel index by `buildRedeemers`, but
`reorgRedeemers` only reindexed spend redeemers, so mint/withdrawal/certificate
redeemers reached `updateRedeemers` with an index the evaluator could not match.
Sentinel-indexed non-spend redeemers are now reindexed by their position within
their purpose; redeemers that already carry a concrete index are left untouched.

Coverage: unit tests for plutus mint, burn (negative quantity), native-script
mint without a redeemer, and multi-policy redeemer reindexing; plus an e2e test
that mints through the builder and submits. The `web-extension` remote-api
property map gains the new method.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rhyslbw rhyslbw force-pushed the feat/export-tx-builder-utils branch from 306b4c4 to e0a82a1 Compare June 17, 2026 15:41
GenericTxBuilder only merged extraSigners into the signing options when
signingOptions were also set. Calling extraSigners() on its own therefore
added the witnesses at sign() but not during fee estimation, producing an
insufficient-fee transaction (e.g. minting under a native policy that
requires an extra signature). Always include extra signers in the
fee-estimation signing options.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rhyslbw rhyslbw merged commit 8faeefa into master Jun 18, 2026
8 of 13 checks passed
@rhyslbw rhyslbw deleted the feat/export-tx-builder-utils branch June 18, 2026 08:56
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.

2 participants