Updating Files on IPFS for ERC721 Contract

I’ve got a standard ERC721 Token Contract going based on openZeppelin’s contract library - everything’s working great thus far, no problems.

Here’s the challenge though:

The Tokens are actually all game assets - swords, shields, spells, etc., and as the player advances through the game his/her assets gain powers which means the Metadata for those assets needs to be updated to reflect those changes.

-The Metadata for each Token will be in its’ own unique .JSON file, with the following naming convention:

token1-Metadata.json
token2-Metadata.json

token999-Metadata.json
token1000-Metadata.json

etc.

-All these JSON files will be stored in a single folder on IPFS and then published on IPNS using my PEER ID.
–>Using IPNS ensures that the URL to this folder will never change - even as the contents of the folder at that URL do. And that means I can hard-code that URL to my smart-contract’s “tokenURI” method so that it returns the URL for any given Token’s JSON-Metadata file by simply concatenating that token’s ID number to a base URI, as follows:

tokenURI = baseURL + “/token” + tokenIDNumber + “-Metadata.json”;

-So, when the properties of any given game-asset have to be updated, the smart-contract will obviously take care of writing and committing those updates to the Blockchain. But that game-asset’s corresponding .JSON metadata file will also have to be updated on IPFS+IPNS.

In order to do this, the updated metadata .JSON file - and the folder that contains it and all the other metadata files, will have to be re-uploaded to IPFS and then republished on IPNS so that the new updated data is served to the world.

My question then is two-fold:

  1. Is there a way to automate this process? Meaning, is it possible to have the contract call a method that not only updates a given Token’s .JSON Metadata file, but then also automatically re-uploads that file and it’s containing folder to IPFS, waits for that to return, and then republishes everything to IPNS? (And do I have to un-pin and then re-pin every file I’m serving?)

  2. If so, would this be done using a Server-side script? (I’m ok with regular, front-end vanilla JS, but I know very little about Node JS. I can also do some basic PHP.)

  3. When it comes to IPFS + IPNS, when changes such as the ones I’m proposing are made to a folder I’m serving from my IPFS node, will all the other Nodes also serving it automatically be updated as well?

And I guess ultimately I’m wondering: is this the best way to handle what my game needs? Is there some other, completely different approach to handling this requirement of updating Metadata .JSON files that I’m overlooking?

Would appreciate any and all help!

@Soren74 , I want to work with you … I have not work the ERC721 part yet but I have done the IPFS+IPNS side :slight_smile: I also want to register and maintain NFTs on the IPFS.

I made a quick code to demonstrate how one can publish a folder and make it visible to the network. The codepen below takes your MTF /public folder and publish it on IPNS

See the Pen Public Folders by Michel on CodePen.

OK, sounds good - let me check out what you did!