<blockquote>
<p>Does Cardano allow for appending metadata like an arbitrary hash string to a transaction?</p>
</blockquote>
<p>I believe you can do this without needing any tokens/NFTs by just making a transaction that has the metadata attached:</p>
<p><a href="https://developers.cardano.org/docs/transaction-metadata/" rel="nofollow noreferrer">https://developers.cardano.org/docs/transaction-metadata/</a></p>
<p>This can be done using the <code>--metadata-json-file</code> switch when building the transaction:</p>
<pre><code>cardano-cli transaction build-raw \
  --tx-in dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5#0 \
  --tx-out $(cat payment.addr)+0 \
  --metadata-json-file metadata.json \
  --fee 0 \
  --out-file tx.draft
</code></pre>
<p><a href="https://developers.cardano.org/docs/transaction-metadata/how-to-create-a-metadata-transaction-cli#submit-to-blockchain" rel="nofollow noreferrer">https://developers.cardano.org/docs/transaction-metadata/how-to-create-a-metadata-transaction-cli#submit-to-blockchain</a></p>

CC BY-SA 4.0
2021-07-23T23:05:17.980Z
This is great. TIL.
Mitchell Turner
CC BY-SA 4.0
2021-07-24T08:59:01.720Z
It really is! Thanks a lot! I wonder how I could miss this reading through the docs...
bkis
CC BY-SA 4.0
2021-07-23T22:48:39.217Z
2021-07-23T22:48:39.217Z
Danny Tuppeny - CODER
<p>I'm sure there is more than one way to do this. Tokens can include metadata and depending on what behavior you want you could structure it different ways.</p>
<p>A couple of options come to mind:</p>
<ol>
<li>Use the <a href="https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/cardano-node-cli-reference.md" rel="nofollow noreferrer">Cardano CLI</a> to add hash string to the metadata of a token</li>
<li>Write a smart contract that owns an NFT with the hash string as data</li>
</ol>
<p>I would first look at the Cardano CLI and see if creating a simple NFT would be good enough for you needs. It's been a minute since I dug into that stuff, so not positive if it will be enough.</p>
<p>If you wanted to do this with a Plutus smart contract, you could have an NFT containing the data owned by the script. This would allow other people, and in theory other smart contracts, to read the hash.</p>
<p>This could look similar to the <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/b50b196d57dc35559b7526fe17b49dd2ba4790bc/code/week06/src/Week06/Oracle/Core.hs" rel="nofollow noreferrer">Oracle Example</a> from the Plutus Pioneers Program. Yours would be simpler because it wouldn't allow the creator to update the value like an oracle.</p>
<p>Essentially it will allow people to consume the hash data on the NFT as long as they return it in the same state they found it. This could also guarantee that you can always find it at the same place, rather than some NFT that could be transferred to different wallets.</p>
<p>Full discretion, this isn't trivial and you'd need to learn how to write/modify the smart contract as well as deploy it. Not to mention, smart contracts are only available on limited test networks as of writing this.</p>
<p>Hope this helps :)</p>

CC BY-SA 4.0
2021-07-24T09:01:04.947Z
Thank you for your answer, it was helpful in that it added some good ideas to the case. I think you'll understand I accepted the other answer for it's significantly smaller overhead, though :)
bkis
CC BY-SA 4.0
2021-07-23T20:53:28.553Z
2021-07-23T20:53:28.553Z
Mitchell Turner
<p>I have an interesting use case for permanently storing an arbitrary hash string somewhere &quot;reliable&quot; publicly and, very important, with a trustworthy timestamp. For me, this sounds like a case for a blockchain application. As I feel a diffuse kind of sympathy for the Cardano project, i thought &quot;why not start here&quot;. Let me explain a bit:</p>
<p>The idea is to create a strong hash (SHA2-256 or the like) of arbitrary data (text files, photos, combinations of these, ...). This part is easy. I don't need a blockchain for that and there are many well established standards for doing this. But now I also want to be able to reliably prove, forever, 'til eternity, that this specific hash existed at a certain time.</p>
<p>My first thought was, well, couldn't I just push this hash to a blockchain somehow? I mean, each transaction has a public timestamp that can't be messed with, right? Does Cardano allow for appending metadata like an arbitrary hash string to a transaction? Should I mint an NFT which holds this data? Then again, wouldn't that be overkill for my use case? What are the technical possibilities I could try to work with, here?</p>
<p>I am a developer, but my insights in blockchain technology are quite rudimentary. So I hope that someone can help me out by pointing me in the right direction. Thank you in advance!</p>

<nft><native-assets><blockchain><metadata>
How to permanently persist an arbitrary hash string in the blockchain?
# How to permanently persist an arbitrary hash string in the blockchain?

(Asked by: username_0 on 2021-07-22)

I have an interesting use case for permanently storing an arbitrary hash string somewhere "reliable" publicly and, very important, with a trustworthy timestamp. For me, this sounds like a case for a blockchain application. As I feel a diffuse kind of sympathy for the Cardano project, i thought "why not start here". Let me explain a bit:

The idea is to create a strong hash (SHA2-256 or the like) of arbitrary data (text files, photos, combinations of these, ...). This part is easy. I don't need a blockchain for that and there are many well established standards for doing this. But now I also want to be able to reliably prove, forever, 'til eternity, that this specific hash existed at a certain time.

My first thought was, well, couldn't I just push this hash to a blockchain somehow? I mean, each transaction has a public timestamp that can't be messed with, right? Does Cardano allow for appending metadata like an arbitrary hash string to a transaction? Should I mint an NFT which holds this data? Then again, wouldn't that be overkill for my use case? What are the technical possibilities I could try to work with, here?

I am a developer, but my insights in blockchain technology are quite rudimentary. So I hope that someone can help me out by pointing me in the right direction. Thank you in advance!

**Tags:** nft, native-assets, blockchain, metadata

---

## 2 answers

### Answer by username_1 on 2021-07-23. Score: 3 | Accepted answer

Does Cardano allow for appending metadata like an arbitrary hash string to a transaction?

I believe you can do this without needing any tokens/NFTs by just making a transaction that has the metadata attached:
https://developers.cardano.org/docs/transaction-metadata/
This can be done using the --metadata-json-file switch when building the transaction:
cardano-cli transaction build-raw \
  --tx-in dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5#0 \
  --tx-out $(cat payment.addr)+0 \
  --metadata-json-file metadata.json \
  --fee 0 \
  --out-file tx.draft

https://developers.cardano.org/docs/transaction-metadata/how-to-create-a-metadata-transaction-cli#submit-to-blockchain

> **Comments:**
> **username_2**: This is great. TIL.  
> **username_0**: It really is! Thanks a lot! I wonder how I could miss this reading through the docs...  

---

### Answer by username_2 on 2021-07-23. Score: 2

I'm sure there is more than one way to do this. Tokens can include metadata and depending on what behavior you want you could structure it different ways.

A couple of options come to mind:

1. Use the [Cardano CLI](https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/cardano-node-cli-reference.md) to add hash string to the metadata of a token
2. Write a smart contract that owns an NFT with the hash string as data

I would first look at the Cardano CLI and see if creating a simple NFT would be good enough for you needs. It's been a minute since I dug into that stuff, so not positive if it will be enough.

If you wanted to do this with a Plutus smart contract, you could have an NFT containing the data owned by the script. This would allow other people, and in theory other smart contracts, to read the hash.

This could look similar to the [Oracle Example](https://github.com/input-output-hk/plutus-pioneer-program/blob/b50b196d57dc35559b7526fe17b49dd2ba4790bc/code/week06/src/Week06/Oracle/Core.hs) from the Plutus Pioneers Program. Yours would be simpler because it wouldn't allow the creator to update the value like an oracle.

Essentially it will allow people to consume the hash data on the NFT as long as they return it in the same state they found it. This could also guarantee that you can always find it at the same place, rather than some NFT that could be transferred to different wallets.

Full discretion, this isn't trivial and you'd need to learn how to write/modify the smart contract as well as deploy it. Not to mention, smart contracts are only available on limited test networks as of writing this.

Hope this helps :)

> **Comments:**
> **username_0**: Thank you for your answer, it was helpful in that it added some good ideas to the case. I think you'll understand I accepted the other answer for it's significantly smaller overhead, though :)  

---

