Resolve a Cardano script witness from a reference output

A transaction can use a script stored on another output instead of carrying a fresh copy of its bytes. The builder still needs the exact script required by the spending purpose.

Match the referenced script hash

Resolve reference output B and inspect its attached script and language. Compute its ledger script hash and compare it with the payment script credential locking A. Include B as a reference input in the built transaction.

spend: script-locked UTxO A
read:  reference UTxO B carrying validator script S

Matching B’s address is insufficient. The attached reference script is the witness source, and the address locking B can be unrelated to the validator for A. Keep any required redeemer and datum in the appropriate places.

Check the lifetime and actual cost

B must remain unspent until the transaction is validated. Reusing its script can reduce serialized witness bytes, but total fees depend on era rules, reference-script fees and execution units. Calculate the final fee on the actual transaction. cips.cardano.org Cardano CIP-33