How to check if an IPFS object is on your local node

I’m currently looking into ways to quickly check if a given IPFS object (i.e. an IPFS hash) is on your node.

One command I found is ipfs object stat <hash>
If the object is on your node, whether pinned or just cached, ipfs will immediately print the object stats like cumulative size. For objects not on your node, stats might still be printed eventually, but it will take longer, so you could then timeout the ipfs object stat command, but it would be better, if ipfs just returned an error like “nope, not on your local node”.

Is there a command like this?

4 Likes

Unfortunately, not at the moment.

I have a need of such a facility too.

1 Like

It’s not necessarily the most efficient, but I think you can do this with ipfs refs local | grep <hash>.

Reference: https://github.com/ipfs/faq/issues/155

3 Likes

Bumping this old thread because there’s better info now and I noticed a user asking about this on the IPFS IRC.

You can do this using the --offline flag. e.g. ipfs object stat <cid> --offline (Note: the offline flag works all over the place so this will work for the block and dag APIs as well).