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:
-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:
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?)
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.)
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!