Gra Fun
  • 🤩Welcome to GraFun
  • 📈Fair Curve
    • 🔄BNB redemption
    • 👑Meme DAO
  • 📊Classic curve
  • 🎯Alpha Launch
  • 🚀 How to Launch
    • 🏦 Service Fees
  • 🛠️Tech Guide
    • 🔄IPFS Cache Data Upload and Synchronization Guide
    • 🧩CID Format
  • ⚖️Terms of Use
Powered by GitBook
On this page
  1. Tech Guide

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()
PreviousIPFS Cache Data Upload and Synchronization GuideNextTerms of Use

Last updated 5 months ago

🛠️
🧩