# IPFS hash verification in nodejs

**URL:** <https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708>\
**Category:** Help\
**Tags:** js-ipfs\
**Created:** [April 19, 2018, 12:41pm UTC](https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708 "2018-04-19T12:41:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk89](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tk89](https://discuss.ipfs.tech/u/tk89)\
**Post date:** [April 19, 2018, 12:41pm UTC](https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708/1 "2018-04-19T12:41:49Z")

</div>

I want to develop a nodejs app in which a user stores a file on IPFS and gives the hash to the app.  
What I would like to do is to verify that the contents under this given hash produce the same hash, something similar to verifying the checksum.  
Is there a way to do it using the ipfs-api module?

For example:

A user writes a “Hello world” string in the “data.txt” file, adds the file on IPFS and gets the hash: `QmWpXFXgii2CfYMBXj9jihPcokpFhwCjGQqOipZ1LVGgTU`

Then he runs my app with the IPFS hash:  
`node myapp.js QmWpXFXgii2CfYMBXj9jihPcokpFhwCjGQqOipZ1LVGgTU`

I would like to verify that the contents under this hash are “Hello world” and he didn’t provide another hash.

---

<div class="post-metadata">

**Author:** ![vmx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/vmx/32/9772_2.png) [@vmx](https://discuss.ipfs.tech/u/vmx)\
**Post date:** [April 20, 2018, 10:46am UTC](https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708/2 "2018-04-20T10:46:24Z")

</div>

I’m not sure I really understand what you are after.

Does your app know “Hello world” and you would like to know that hash of it? If yes you could try the “onlyHash” option.

---

<div class="post-metadata">

**Author:** ![tk89](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tk89](https://discuss.ipfs.tech/u/tk89)\
**Post date:** [April 20, 2018, 9:57pm UTC](https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708/3 "2018-04-20T21:57:58Z")

</div>

Basically I want to read from an IPFS hash and get the contents of the file stored under this address, then I want to verify that the contents of the file produce actually the given hash.

In other words, a user claims that a file with “Hello world” gives this hash: `QmWpXFXgii2CfYMBXj9jihPcokpFhwCjGQqOipZ1LVGgTU` but when I read under this hash there is another file with “Hello”.  
Actually I want to make sure that the hash that the user gives me is what he claims to be.

PS. In ipfs-api npm package I didn’t find an “onlyHash” option…

---

<div class="post-metadata">

**Author:** ![vmx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/vmx/32/9772_2.png) [@vmx](https://discuss.ipfs.tech/u/vmx)\
**Post date:** [April 23, 2018, 11:53am UTC](https://discuss.ipfs.tech/t/ipfs-hash-verification-in-nodejs/2708/4 "2018-04-23T11:53:57Z")

</div>

So it sounds like you want the “only hash” option. You would take the file and then `add` with `onlyHash: true` and you’ll get the hash of the file back. Then you can verify if it’s the same.

Though that shouldn’t actually be needed as if you retrieve a file with a certain hash from IPFS it’s guaranteed that the contents hashes to that hash.

> [@tk89](#):
>
> PS. In ipfs-api npm package I didn’t find an “onlyHash” option…

If you run `jsipfs add --help` you’ll see the `--only-hash` option which maps to `onlyHash` when you use the module.
