user2335: I am reading through the haddock documentation to find the way metadata is attached to a transaction. In this documentation (1) we have
data Blockchain = [Block]
data Block = [OnChainTx]

Where

and

Now my question is, where and how is metadata appended? My guess is that the only place it could be is in the txData field. And if so, take the example of NFT metadata. By CIP 25 it is of a certain JSON format. Is this than converted via JSON -> data -> BuiltinData and finally wrapped in the Datum type?

user6305: The transaction metadata lives outside of the transaction body, inside of the auxiliary_data. In the Babbage ledger era, you can see this in the wire spec (CDDL)
here
In particular, the metadata is defined
here.
In Haskell, you can see that the metadata is
defined
as a map from Word64 to Metadatum.
(I've chosen the Alonzo auxiliary data type to link to here, which is re-used by the Babbage era).
And Metadatum is the JSON-like structure defined
here.

Note that the transaction metadata is a different type than the Datum type used by Plutus, though the structure is nearly identical. (txData contains Datum, not Metadatum.)

CIP-25 is provides a schema for expressing NFT Metadata within the transaction metadata. So in particular, it specifies using the number 271 as the transaction metadatum label, and proceeds to specify the rest of the structure. The cardano-cli is capable of converting JSON metadata files into the correct wire format, and attaching it to a transaction (with the hash in the transaction body, so that it cannot be corrupted).

2335: <p>I am reading through the haddock documentation to find the way metadata is attached to a transaction. In this documentation <a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger/html/Ledger-Blockchain.html" rel="nofollow noreferrer">(1)</a> we have</p>
<pre><code>data Blockchain = [Block]
data Block = [OnChainTx]
</code></pre>
<p>Where</p>
<p><a href="https://i.stack.imgur.com/ZQG5U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQG5U.png" alt="OnChainTx definition" /></a></p>
<p>and</p>
<p><a href="https://i.stack.imgur.com/yaftL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yaftL.png" alt="Tx definition" /></a></p>
<p>Now my question is, where and how is metadata appended? My guess is that the only place it could be is in the <code>txData</code> field. And if so, take the example of NFT metadata. By CIP 25 it is of a certain JSON format. Is this than converted via JSON -&gt; <code>data</code> -&gt; <code>BuiltinData</code> and finally wrapped in the <code>Datum</code> type?</p>
 6305: <p>The transaction metadata lives outside of the transaction body, inside of the <code>auxiliary_data</code>. In the Babbage ledger era, you can see this in the wire spec (CDDL)
<a href="https://github.com/input-output-hk/cardano-ledger/blob/fc4734c93d60158f2db04b416266268d0261c443/eras/babbage/test-suite/cddl-files/babbage.cddl#L17" rel="nofollow noreferrer">here</a>
In particular, the metadata is defined
<a href="https://github.com/input-output-hk/cardano-ledger/blob/fc4734c93d60158f2db04b416266268d0261c443/eras/babbage/test-suite/cddl-files/babbage.cddl#L329-L337" rel="nofollow noreferrer">here</a>.</p>
<p>In Haskell, you can see that the metadata is
<a href="https://github.com/input-output-hk/cardano-ledger/blob/fc4734c93d60158f2db04b416266268d0261c443/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs#L241y" rel="nofollow noreferrer">defined</a>
as a map from <code>Word64</code> to <code>Metadatum</code>.
(I've chosen the Alonzo auxiliary data type to link to here, which is re-used by the Babbage era).</p>
<p>And <code>Metadatum</code> is the JSON-like structure defined
<a href="https://github.com/input-output-hk/cardano-ledger/blob/fc4734c93d60158f2db04b416266268d0261c443/eras/shelley/impl/src/Cardano/Ledger/Shelley/Metadata.hs#L65-L72" rel="nofollow noreferrer">here</a>.</p>
<hr />
<p><strong>Note</strong> that the transaction metadata is a different type than the <code>Datum</code> type used by Plutus, though the structure is nearly identical. (<code>txData</code> contains <code>Datum</code>, not <code>Metadatum</code>.)</p>
<hr />
<p>CIP-25 is provides a schema for expressing NFT Metadata within the transaction metadata. So in particular, it specifies using the number <code>271</code> as the transaction metadatum label, and proceeds to specify the rest of the structure. The <code>cardano-cli</code> is capable of converting JSON metadata files into the correct wire format, and attaching it to a transaction (with the hash in the transaction body, so that it cannot be corrupted).</p>
