Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use this to create a V0 CID? #20

Closed
MoonBoi9001 opened this issue Sep 5, 2021 · 4 comments
Closed

How do I use this to create a V0 CID? #20

MoonBoi9001 opened this issue Sep 5, 2021 · 4 comments

Comments

@MoonBoi9001
Copy link

MoonBoi9001 commented Sep 5, 2021

It seems that the CID created is of the format V1 CID. Is it possible to instead generate a V0 CID?

@MoonBoi9001
Copy link
Author

ipfs add --only-hash --recursive

the above does exactly what I need, leaving this for someone else incase they want it

take out --recursive if you don't want the hash for every file in the directory

@JulienPlanchetCoineo
Copy link

Did you find a way to call recursive from the API ?

@MoonBoi9001
Copy link
Author

Did you find a way to call recursive from the API ?

Hey man yes I did, I actually found a better way that doesn't require it as well. When you upload files to ipfs inside a folder you can type the Cid of the folder into the URL and then append /X to the end to access the file inside that folder.

For example if your file is called 1.png you can do f{URL}+ "/1.png" to access it. This way you don't need to compute thousands of different CID's.

@alanshaw
Copy link
Owner

alanshaw commented Dec 1, 2021

Yes there's a --cid-version option in the CLI:

$ ipfs-only-hash --help

  Just enough code to calculate the IPFS hash for some data

  Usage
    # get the cid v1 for the file 
    $ ipfs-only-hash <file>

    # get the cid v0 for data from stdin
    $ echo "hello world" | ipfs-only-hash --cid-version 0


$ echo "hello world" | ipfs-only-hash --cid-version 0
QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o

If you're using this programmatically I believe it outputs v0 CIDs by default but you can pass cidVersion: 0 as an option if not. Docs for that are here: https://github.com/alanshaw/ipfs-only-hash#hashofinput-options-promisestring

I'd love a PR to add directory support...or maybe fix up this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants