I’m building a small blockchain app where i plan to store files on IPFS, my question is if i store the following:
{
name: "The name",
description: "Here some ramdom description",
file: "https://ipfs.infura.io/ipfs/Qm..."
}
If i needs to change the name or description, how do i proceed without having to change the content address/cid each time? with IPNS? where can i see exemple on how to handle this with js-ipfs?
When adding a file on IPFS, you can add only the file, or the file and its name.
So just add the file itself on IPFS, and reference it on your blockchain.
That way, updating its metadata onchain won’t change its CID on IPFS.
Thank you for the answer, its actually what i did initially, just add the file on ipfs and store the file CID and all metadata together onchain but i saw some standard recommanding different structure, for exemple: https://ipfs.infura.io/ipfs/QmNcjCT1xcXaUAY9z4sduRy6KnuUepuKp4jWXmRwMuMiFF
Here i was wondering how do you update metadata then without changing the cid.
you store the file on IPFS, all metadata onchain. Pro: changing the metadata doesn’t change the CID. Con: you don’t have metadata embeded from IPFS, client need the chain to get the extra info.
you store the file with its metadata on IPFS, and reference it on chain. On change, you put a new transaction referencing the new CID (and the old if you want tracability). Pro: client have everything upon fetching on IPFS. Con: they still need the chain, or the CID might not be the last.
you store an IPNS record onchain referencing the curent version of the file. Pro: update is free(no onchain transaction), and people just need to know the IPNS adress once and for all. Con: since you can put whatever you want behind it and change it, client have to trust that you won’t put trash behind it at some point in the future.
Thanks a lot for this detailled and very helpfull infos. I started with 1 so far, i may continue with it as i rather go with the less trust required. Will take some time to study it though, thanks a lot.