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

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!

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)

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

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 :slight_smile:

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.

→ 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.

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.

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 and they have an API for that see details below:{datum_hash}/get