<p>The answer is no.</p>
<p>A TxId is hash digest (blake2b-256) of the serialized transaction body. By construction, a hash is non-reversible (<a href="https://en.wikipedia.org/wiki/Cryptographic_hash_function" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Cryptographic_hash_function</a>).</p>
<p>In order to find back a transaction from a TxId, you need an index which keeps track of transactions and enable looking them up.</p>

CC BY-SA 4.0
2021-11-10T08:22:42.747Z
2021-11-10T08:22:42.747Z
KtorZ
<p>The validator script has only access to the <code>ScriptContext</code> which contains <code>TxInfo</code> and <code>ScriptPurpose</code>.</p>
<p>TxInfo contains the following:</p>
<pre><code>data TxInfo = TxInfo
  { txInfoInputs      :: [TxInInfo] -- ^ Transaction inputs
  , txInfoOutputs     :: [TxOut] -- ^ Transaction outputs
  , txInfoFee         :: Value -- ^ The fee paid by this transaction.
  , txInfoMint        :: Value -- ^ The 'Value' minted by this transaction.
  , txInfoDCert       :: [DCert] -- ^ Digests of certificates included in this transaction
  , txInfoWdrl        :: [(StakingCredential, Integer)] -- ^ Withdrawals
  , txInfoValidRange  :: POSIXTimeRange -- ^ The valid range for the transaction.
  , txInfoSignatories :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
  , txInfoData        :: [(DatumHash, Datum)]
  , txInfoId          :: TxId
  } deriving stock (Generic, Haskell.Show, Haskell.Eq)
</code></pre>
<p>So it looks to me as if you cannot access the <code>Tx</code> in your validator.</p>

CC BY-SA 4.0
2021-10-10T23:22:01.357Z
I think you you might be a little confused about what I'm asking. After you submit a transaction with ```submitTxConstraints``` (off chain code) it returns a type of Tx. You can then compress that Tx into a TxId. Im wondering if there is a way to go from that TxId back to Tx. Everything here is off chain code so the validator scope should not matter.
Isaac Padberg
CC BY-SA 4.0
2021-10-10T22:06:53.030Z
2021-10-10T22:06:53.030Z
Jey
<p>I looked through the Plutus GitHub and found some info, but I cannot decode it.<a href="https://github.com/input-output-hk/plutus/blob/1efbb276ef1a10ca6961d0fd32e6141e9798bd11/plutus-ledger/src/Ledger/Tx.hs" rel="nofollow noreferrer">plutus/plutus-ledger/src/Ledger/Tx.hs</a></p>
<p>Here it is:</p>
<pre><code>  encode (SomeTx tx eraInMode) = encodedMode eraInMode &lt;&gt; Encoding (TkBytes (C.serialiseToCBOR tx))
    where
      encodedMode :: C.EraInMode era C.CardanoMode -&gt; Encoding
      -- 0 and 1 are for ByronEraInByronMode and ShelleyEraInShelleyMode
      encodedMode C.ByronEraInCardanoMode   = Encoding (TkSimple 2)
      encodedMode C.ShelleyEraInCardanoMode = Encoding (TkSimple 3)
      encodedMode C.AllegraEraInCardanoMode = Encoding (TkSimple 4)
      encodedMode C.MaryEraInCardanoMode    = Encoding (TkSimple 5)
      encodedMode C.AlonzoEraInCardanoMode  = Encoding (TkSimple 6)
  decode = do
    w &lt;- decodeSimple
    case w of
      2 -&gt; decodeTx C.AsByronEra C.ByronEraInCardanoMode
      3 -&gt; decodeTx C.AsShelleyEra C.ShelleyEraInCardanoMode
      4 -&gt; decodeTx C.AsAllegraEra C.AllegraEraInCardanoMode
      5 -&gt; decodeTx C.AsMaryEra C.MaryEraInCardanoMode
      6 -&gt; decodeTx C.AsAlonzoEra C.AlonzoEraInCardanoMode
      _ -&gt; fail &quot;Unexpected value while decoding Cardano.Api.EraInMode&quot;
    where
      decodeTx :: C.IsCardanoEra era =&gt; C.AsType era -&gt; C.EraInMode era C.CardanoMode -&gt; Decoder s SomeCardanoApiTx
      decodeTx asType eraInMode = do
        bytes &lt;- decodeBytes
        tx &lt;- either (const $ fail &quot;Failed to decode Cardano.Api.Tx&quot;) pure $ C.deserialiseFromCBOR (C.AsTx asType) bytes
        pure $ SomeTx tx eraInMode
</code></pre>
<p>How do you go about using something like this?</p>
<p>Thanks!</p>

<txid><tx><decode>
Is there a way to go from a TxId to a Tx?
# Is there a way to go from a TxId to a Tx?

(Asked by: username_0 on 2021-10-10)

I looked through the Plutus GitHub and found some info, but I cannot decode it.plutus/plutus-ledger/src/Ledger/Tx.hs
Here it is:
  encode (SomeTx tx eraInMode) = encodedMode eraInMode <> Encoding (TkBytes (C.serialiseToCBOR tx))
    where
      encodedMode :: C.EraInMode era C.CardanoMode -> Encoding
      -- 0 and 1 are for ByronEraInByronMode and ShelleyEraInShelleyMode
      encodedMode C.ByronEraInCardanoMode   = Encoding (TkSimple 2)
      encodedMode C.ShelleyEraInCardanoMode = Encoding (TkSimple 3)
      encodedMode C.AllegraEraInCardanoMode = Encoding (TkSimple 4)
      encodedMode C.MaryEraInCardanoMode    = Encoding (TkSimple 5)
      encodedMode C.AlonzoEraInCardanoMode  = Encoding (TkSimple 6)
  decode = do
    w <- decodeSimple
    case w of
      2 -> decodeTx C.AsByronEra C.ByronEraInCardanoMode
      3 -> decodeTx C.AsShelleyEra C.ShelleyEraInCardanoMode
      4 -> decodeTx C.AsAllegraEra C.AllegraEraInCardanoMode
      5 -> decodeTx C.AsMaryEra C.MaryEraInCardanoMode
      6 -> decodeTx C.AsAlonzoEra C.AlonzoEraInCardanoMode
      _ -> fail "Unexpected value while decoding Cardano.Api.EraInMode"
    where
      decodeTx :: C.IsCardanoEra era => C.AsType era -> C.EraInMode era C.CardanoMode -> Decoder s SomeCardanoApiTx
      decodeTx asType eraInMode = do
        bytes <- decodeBytes
        tx <- either (const $ fail "Failed to decode Cardano.Api.Tx") pure $ C.deserialiseFromCBOR (C.AsTx asType) bytes
        pure $ SomeTx tx eraInMode

How do you go about using something like this?
Thanks!

**Tags:** txid, tx, decode

---

## 2 answers

### Answer by username_1 on 2021-11-10. Score: 2

The answer is no.

A TxId is hash digest (blake2b-256) of the serialized transaction body. By construction, a hash is non-reversible (<https://en.wikipedia.org/wiki/Cryptographic_hash_function>).

In order to find back a transaction from a TxId, you need an index which keeps track of transactions and enable looking them up.


---

### Answer by username_2 on 2021-10-10. Score: 0

The validator script has only access to the ScriptContext which contains TxInfo and ScriptPurpose.
TxInfo contains the following:
data TxInfo = TxInfo
  { txInfoInputs      :: [TxInInfo] -- ^ Transaction inputs
  , txInfoOutputs     :: [TxOut] -- ^ Transaction outputs
  , txInfoFee         :: Value -- ^ The fee paid by this transaction.
  , txInfoMint        :: Value -- ^ The 'Value' minted by this transaction.
  , txInfoDCert       :: [DCert] -- ^ Digests of certificates included in this transaction
  , txInfoWdrl        :: [(StakingCredential, Integer)] -- ^ Withdrawals
  , txInfoValidRange  :: POSIXTimeRange -- ^ The valid range for the transaction.
  , txInfoSignatories :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
  , txInfoData        :: [(DatumHash, Datum)]
  , txInfoId          :: TxId
  } deriving stock (Generic, Haskell.Show, Haskell.Eq)

So it looks to me as if you cannot access the Tx in your validator.

> **Comments:**
> **username_0**: I think you you might be a little confused about what I'm asking. After you submit a transaction with ```submitTxConstraints``` (off chain code) it returns a type of Tx. You can then compress that Tx into a TxId. Im wondering if there is a way to go from that TxId back to Tx. Everything here is off chain code so the validator scope should not matter.  

---

