From 510ca0d8572b3537fa57e97e8ef5dc7d588e57c7 Mon Sep 17 00:00:00 2001 From: Danny O'Brien Date: Thu, 28 Aug 2025 13:14:25 -0700 Subject: [PATCH 1/2] 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/concepts/content-addressing.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/concepts/content-addressing.md b/docs/concepts/content-addressing.md index 92a74f0b7..bb05b4f32 100644 --- a/docs/concepts/content-addressing.md +++ b/docs/concepts/content-addressing.md @@ -147,6 +147,13 @@ v0.toV1().toString() ### v1 to v0 +Similarly, the built-in `ipfs cid format` command can be used to convert the other way from the command line: + +``` +$ ipfs cid format -v 0 bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi +QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR +``` + 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: ```js From cad2d86a83421540de712637298ee92f14f38eed Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 25 Sep 2025 20:47:51 +0200 Subject: [PATCH 2/2] 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 --- docs/concepts/content-addressing.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/concepts/content-addressing.md b/docs/concepts/content-addressing.md index bb05b4f32..3edeea661 100644 --- a/docs/concepts/content-addressing.md +++ b/docs/concepts/content-addressing.md @@ -145,15 +145,19 @@ v0.toV1().toString() //> 'bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku' ``` -### v1 to v0 +### v1 to v0 -Similarly, the built-in `ipfs cid format` command can be used to convert the other way from the command line: +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. + +The built-in `ipfs cid format` command can be used to convert `dag-pb` from CIDv1 to CIDv0 from the command line: ``` $ ipfs cid format -v 0 bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR ``` +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. + 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: ```js