# Fundamental Question: How do I get the datum of a utxo off chain?

**URL:** <https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002>\
**Category:** Smart Contracts\
**Tags:** plutus\
**Created:** [15 December 2021 06:11 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002 "2021-12-15T06:11:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![theganant](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/theganant/32/48001_2.png) [@theganant](https://forum.cardano.org/u/theganant)\
**Post date:** [15 December 2021 06:11 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/1 "2021-12-15T06:11:04Z")

</div>

One fundamental question that I don’t seem to see many conclusive answers to is “How do I get the datum of a utxo off chain?”

I am build a transaction using `cardano-cli` using the `--tx-out-datum-embed-file` flag. If I want another party to spend this utxo, they need to read the datum at the utxo in order to update it accordingly. How would they do this in a decentralized, trustless manner? Seems like this question is at the root of trustless, powerful smart contract engineering on Cardano, but I can’t seem to find any answers to it.

Any help is appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![tomdx](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/tomdx/32/44498_2.png) [@tomdx](https://forum.cardano.org/u/tomdx)\
**Post date:** [15 December 2021 09:59 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/2 "2021-12-15T09:59:18Z")

</div>

I was of the impression that the datum value that produces the datum hash associated with an UTxO is somewhat of a “shared secret” i.e. the other party must know the datum value that produces the hash in order to unlock the UTxO. The chain does not know the value, it only knows the hash. (I could be wrong with this)

---

<div class="post-metadata">

**Author:** ![\_ilap](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/_ilap/32/80886_2.png) [@\_ilap](https://forum.cardano.org/u/_ilap)\
**Post date:** [15 December 2021 11:02 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/3 "2021-12-15T11:02:34Z")

</div>

Unfortunately, it’s not a `shared-secret` until it is exposed either by added to the tx as `--tx-in-datum-{file,value}` (when any input as a transaction input uses that datumHash) **or** as @theganant wrote it is (optionaly) added to the same tx’s witness set when the transaction output is created (as a transaction output).

Meaning, every 3rd-party tool (ChainIndex, DB-Sync, explorers) will be able to access to the datum located on-chain, but only after it’s exposed somehow.

Also, there is a [CIP for inline datum](https://github.com/cardano-foundation/CIPs/blob/08aafcf6565952411379fe81a626777260782fc7/CIP-0032/README.md)

---

<div class="post-metadata">

**Author:** ![theganant](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/theganant/32/48001_2.png) [@theganant](https://forum.cardano.org/u/theganant)\
**Post date:** [15 December 2021 20:09 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/4 "2021-12-15T20:09:18Z")

</div>

Thanks for the response!  
I’m specifically asking about the procedure for retrieving the datum from a transaction.  
Can you explain how I would get the datum from one of those tools?

Also, I have had people suggest to me to embed the datum in the metadata of the transaction, but since there is no enforcement in Plutus of what the metadata should be, another party could not update the metadata accordingly and make the utxo unspendable.

Simply, I’m looking for a procedure for trustlessly retrieving datum from a utxo with Cardano’s security.

Upvoted the CIP 🙂

---

<div class="post-metadata">

**Author:** ![tigrpool.com](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/tigrpool.com/32/26328_2.png) [@tigrpool.com](https://forum.cardano.org/u/tigrpool.com)\
**Post date:** [16 December 2021 08:25 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/5 "2021-12-16T08:25:03Z")

</div>

> [@theganant](#):
>
> `--tx-out-datum-embed-file`

Does someone know on which table the datum is ?

I did a quick scan through all the tables but did not find a field based on the cardano-db-sync database.

What i found was a field “DataHash” and “AddressHasScript” on the TxOut.

[https://mainnet.cutymals.com/odata/TransactionsOut?includeTxSender=false&includeTxReceiver=true&unspentOnly=false&X-API-KEY=ILoveCutyMals&%24filter=DataHash%20ne%20null&%24orderby=id%20desc](https://mainnet.cutymals.com/odata/TransactionsOut?includeTxSender=false&includeTxReceiver=true&unspentOnly=false&X-API-KEY=ILoveCutyMals&%24filter=DataHash%20ne%20null&%24orderby=id%20desc)

→ The query orders the txouts descending and filters for all entries where “DataHash ne null” which means all fields were a value for DataHash exists.

```auto
value": [
    {
      "Id": 49341120,
      "TxId": 21314789,
      "Index": 0,
      "Address": "addr1z8n7s4g2ux528ch6ty3sq3nz65706chdvfykun0hf9kyvtq92vl27xmdcqhdvcu632a585gfsgx9h29atl8uhqph2rdsgkfpn3",
      "AddressRaw": "EefoVQrhqKPi+lkjAEZi1Tz9Yu1iSW5N90lsRiwFUz6vG23ALtZjmoq7Q9EJggxbqL1fz8uAN1Db",
      "AddressRawInHex": "11e7e8550ae1a8a3e2fa5923004662d53cfd62ed62496e4df7496c462c05533eaf1b6dc02ed6639a8abb43d109820c5ba8bd5fcfcb803750db",
      "PaymentCred": "5+hVCuGoo+L6WSMARmLVPP1i7WJJbk33SWxGLA==",
      "PaymentCredInHex": "e7e8550ae1a8a3e2fa5923004662d53cfd62ed62496e4df7496c462c",
      "StakeAddressId": 3305663,
      "Value": 1814813,
      "AddressHasScript": true,
      "DataHash": "HIoCR9WBEwG7+fsdy77FXJ2uEXWAe22N/N81VosF3mo="
    },
    {
      "Id": 49328174,
      "TxId": 21311616,
      "Index": 0,
      "Address": "addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3",
      "AddressRaw": "cUpZ69k+pT0bv3+CIyx7AScAoM9Lt42Hnauxogo=",
      "AddressRawInHex": "714a59ebd93ea53d1bbf7f82232c7b012700a0cf4bb78d879dabb1a20a",
      "PaymentCred": "Slnr2T6lPRu/f4IjLHsBJwCgz0u3jYedq7GiCg==",
      "PaymentCredInHex": "4a59ebd93ea53d1bbf7f82232c7b012700a0cf4bb78d879dabb1a20a",
      "StakeAddressId": null,
      "Value": 1851850,
      "AddressHasScript": true,
      "DataHash": "LaqIOqsrk6zYvEEia0IPJb+a8Yyk8dbTYnHW2tbvazs="
    },

```

The database returns it as “Base64” encoded at the moment, but if thats what you need we can translate that, so you would be able to retrieve it via the API.

---

<div class="post-metadata">

**Author:** ![\_ilap](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.cardano.org/_ilap/32/80886_2.png) [@\_ilap](https://forum.cardano.org/u/_ilap)\
**Post date:** [17 December 2021 14:20 UTC](https://forum.cardano.org/t/fundamental-question-how-do-i-get-the-datum-of-a-utxo-off-chain/89002/6 "2021-12-17T14:20:18Z")

</div>

Sorry, I have no clue how could you gather the datum with these 3rd-party tools as I have no any experience with them. Though, it should be very straight forward, if they have some query API directly for datums.

I have just checked [Blockforst.IO](https://blockfrost.io) and they have an API for that see details below:  
[https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1{datum\_hash}/get](https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1%7Bdatum_hash%7D/get)
