Choose the right datum source when spending a Cardano script output

Two outputs can refer to the same Plutus datum but store it differently. A transaction builder needs to inspect the output’s datum option before assembling witnesses.

Differentiate a hash from an inline value

In the example, X commits only to H. For a validator requiring that datum, obtain D, verify that its ledger datum hash matches H and include the necessary datum witness. Y carries D directly for inspection and spending.

output X: datum hash H
output Y: inline datum D, where hash(D) = H

Keep the original Plutus data structure through decoding. A JSON rendering for humans can erase constructor or byte-string distinctions and produce a different hash when reconstructed.

Account for script language and output size

An inline datum contributes to the output size and thus to the minimum lovelace it must carry. Check the transaction’s Plutus language compatibility and applicable era rules before mixing inline outputs with older script versions. cips.cardano.org Cardano CIP-32