Skip to content

Commit a40b064

Browse files
dannyobgammazerolidel
authored
docs: make explicit that you can use ipfs cid format to convert both ways (#2126)
* Make explicit that you can use ipfs cid format to convert both ways It took me a moment to realise that this was possible, so wanted to save that moment for future generations of IPFS newbies. * docs: clarify dag-pb requirement for CIDv1 to CIDv0 conversion add explicit note that conversion from CIDv1 to CIDv0 only works when the CIDv1 uses dag-pb codec, as CIDv0 only supports dag-pb --------- Co-authored-by: Andrew Gillis <[email protected]> Co-authored-by: Marcin Rataj <[email protected]>
1 parent 5a56c1f commit a40b064

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

docs/concepts/content-addressing.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,18 @@ v0.toV1().toString()
145145
//> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
146146
```
147147

148-
### v1 to v0
148+
### v1 to v0
149+
150+
Conversion from CIDv1 to CIDv0 is only possible when the CIDv1 uses the `dag-pb` codec (0x70), as CIDv0 only supports `dag-pb`. CIDs using other codecs like `raw` (0x55), `dag-cbor` (0x71), or `dag-json` (0x0129) cannot be converted to CIDv0.
151+
152+
The built-in `ipfs cid format` command can be used to convert `dag-pb` from CIDv1 to CIDv0 from the command line:
153+
154+
```
155+
$ ipfs cid format -v 0 bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
156+
QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
157+
```
158+
159+
Note: The above example works because `bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi` uses the `dag-pb` codec. Attempting to convert a CIDv1 with a different codec will result in an error.
149160

150161
Given a CID v1, JS users can convert back to v0 using the `toV0()` method provided by the [`multiformats`](https://www.npmjs.com/package/multiformats) library:
151162

0 commit comments

Comments
 (0)