# IPFS tips and hacks

By [N00b21337](https://paragraph.com/@n00b21337) · 2023-01-11

---

### Preserve base URL for use with smart contracts

By default using IPFS Desktop and uploading files will give your shareable links each time different URL, which is a problem when you want to have base URL and just change the last part of the path per token ID. So to solve that you need to use is "Wrap Filenames and Directory Info around Content" [https://dweb-primer.ipfs.io/files-on-ipfs/wrap-directories-around-conte…](https://dweb-primer.ipfs.io/files-on-ipfs/wrap-directories-around-content) which in CLI looks like this.

`$ ipfs add -w mytextfile.txt added QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy mytextfile.txt added QmPvaEQFVvuiaYzkSVUp23iHTQeEUpDaJnP8U7C3PqE57w`

In IPFS desktop you don't have this option but with Pinata service you have this possibility in UI.

Also here is how to use IPNS so you can have fixed base URL even when you change data and add more files [https://dweb-primer.ipfs.io/publishing-changes/modify-republish](https://dweb-primer.ipfs.io/publishing-changes/modify-republish)

And even more how to use DNSLink for more cleaner version of IPFS URL [https://docs.ipfs.io/concepts/dnslink/#publish-content-path](https://docs.ipfs.io/concepts/dnslink/#publish-content-path)

### Versions of CID and how to know which one you are using

**Let's examine two examples of CIDs in their string form:**

**QmY6yj1GsermExDXoosVE3aSPxdMNYr6aKuw3nA8LoWPRS bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi**

Multihash formatting and `base58btc` encoding enabled this first version of the CID, now referred to as Version 0 (`CIDv0`), and its initial `Qm...` characters remain easy to spot. The second example starts with b, the base encoding prefix identifier for base32, which is used by default by most implementations of IPFS. If it starts with b it's base32 and is CIDv1.

You can convert any `CIDv0` to `CIDv1`, because the implicit prefixes from `v0` become explicit in `v1`. However, because `CIDv1` supports multiple codecs and multiple bases and `CIDv0` does not, not all `CIDv1` can be converted to `CIDv0`.

More info on Anatomy of CIDs [https://proto.school/anatomy-of-a-cid/02](https://proto.school/anatomy-of-a-cid/02) Use CID inspector [https://cid.ipfs.io/](https://cid.ipfs.io/)

### Adding files as folder CID0 and CID1 version

When you want to add whole folder to IPFS you  need to use one of this two commands

    ipfs add -r --cid-version=1  .
    

this uses CIDv1 or if you just type in plain

    ipfs add -r .
    

this will add files in your current path and folder where they are with CID0 version.

---

*Originally published on [N00b21337](https://paragraph.com/@n00b21337/ipfs-tips-and-hacks)*
