CID Format
CID format Conversion Guide (node js)
import { CID } from 'multiformats/cid'
import { base32 } from 'multiformats/bases/base32'
async function convertCID(oldCID) {
try {
// Parse the old CID
const parsed = CID.parse(oldCID)
// Create new CIDv1 in base32
const newCID = parsed.toV1()
// Convert to base32 string
return newCID.toString(base32)
} catch (error) {
console.error('Error converting CID:', error)
throw error
}
}
// Usage example
async function main() {
const oldCID = 'QmdfLnJ22TFRPdvqKMirjxgVVRassP9Si8YqpK6nbBcZDw'
try {
const newCID = await convertCID(oldCID)
console.log('Old CID:', oldCID)
console.log('New CIDv1 (Base32):', newCID)
} catch (error) {
console.error('An error occurred:', error)
}
}
main()
Last updated