0

I am building a blockchain game where users can update their character's appearance. This is done by calling a function called updateAppearance in smart contract.

I want to show latest version of that token in my website. For example, if user changes hair of his/her character, I want to change metadata by changing tokenURI.

My best guess is, calculate an string or byte according to current appearance of character and change tokenURI to baseURI + string. But problem with this approach is, I have to upload every single possibility to my server (or IPFS) and for me this is probably not the best way of doing this.

Another thing that comes to my mind is sending request to my server from blockchain (not possible without oracles) but I don't know anything about oracles and I think this approach is bit too complicated for this kind of project.

What would be better approach for this, how should I store metadata in my server?

Edit: I checked CryptoZombies project (awesome btw), they store Zombie's DNA with an integer. Maybe I can store character's appearance and point tokenURI to that DNA string I calculated. Then in my server (ExpressJS), I can dynamically generate image data using that DNA.

0

Rather than changing the tokenURI for every possible permutations, you can change the metadata stored at the location of URI and update tokenURI accordingly.

Assuming that metadata is in JSON format hosted at IPFS. Retrieve that metadata, change the required fields, for e.g "hair_color": "grey" and pin it so you will get a new IPFS hash, replace that in the smart contract tokenURI field and unpin the previous old IPFS hash (i.e hash before changing metadata) so you don't waste resources.

2
  • So, I need to create an Updated event in my contract and in my client, update the json accordingly, right? – Batın Evirgen Apr 11 at 13:43
  • @BatınEvirgen in standard erc721/erc1155 implementation, it doesn't support changing of tokenURI once it is set for specific tokenId, so you will have to edit that login to make it mutable and you can use event if you want to aggregate them or use for any specific purpose. – hack3r_0m Apr 11 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.