Skip to content

feat(builder): spend datum hash outputs - #707

Merged
solidsnakedev merged 10 commits into
mainfrom
feat/spend-datum-hash
Oct 21, 2026
Merged

solidsnakedev merged 10 commits into
mainfrom
feat/spend-datum-hash

Conversation

@solidsnakedev

Copy link
Copy Markdown
Collaborator

Spending an output that holds a datum hash at a Plutus script address failed. The builder left the datum out of the witness set, so the node rejected the transaction with a missing datum. A datum from getDatum also lost the bytes it was fetched with, so writing it with the build's codec options could change its hash.

collectFrom now takes the datums of those inputs in a datums field, and build({ onMissingDatum: "provider" }) fetches the missing ones with provider.getDatum. The builder matches each datum to its input by hashing the bytes it will write. Before coin selection, the build fails when an input's datum is missing or a given datum belongs to no spent input. The default, onMissingDatum: "error", makes no request.

The built-in getDatum records the fetched bytes with OriginalBytes. The witness set and the script data hash write those bytes ahead of the codec options, as inline datums already do. The witness set keeps each datum as the same object, so the bytes survive the witness sets SignBuilder rebuilds. The fake witness set counts the datums toward the fee, and assemble keeps only the transaction's own datums.

Closes #698

@solidsnakedev
solidsnakedev merged commit cd6c9d4 into main Oct 21, 2026
10 checks passed
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.

TxBuilder: spending a datum-hash output leaves the datum out of the witness set

1 participant