Dynamic Metadata is a way of serving metadata in a dynamic way, by having the collection attribute uri set with the special {id} keyword.
Read more about Dynamic Metadata here
Serving metadata in a dynamic way is done in 3 steps:
Please note, if you were already serving metadata dynamically for a collection on Ethereum / JumpNet that is now replicated on Enjin Blockchain, and you want to continue serving the metadata dynamically, you will first have to make some changes to the .json file names in your old CDN due to changes made to the token ID structure.
For that, please skip to this section: Converting to the New Token ID Structure.
Step 1: Hosting the media files
Prepare your collection and tokens media files and upload them on any hosting service or a server. For this example, we are going host the media files in a decentralized way on IPFS using Pinata.cloud.
⚠️ Please note: Pinata.cloud is a third party IPFS pinning service. Enjin is not responsible for any issues or complications that may arise from its use.
- Create a free Pinata account: https://www.pinata.cloud/
- If being asked how you plan to use Pinata, select "I'm not a developer, I'll use the web app"
- Prepare all of your collection and tokens media files into a single folder
- In Pinata.cloud Files Dashboard, click on the "Upload" button at the top right corner, followed by "Folder"
- Select the folder you've prepared in step #3 to upload it.
- Once the media files done uploading, copy the “CID” and save it for the next step.
Step 2: Hosting the metadata .json files
Metadata files consists of a media file, and a .json file pointing to the media file, as well as other data such as name, description, attributes, etc.
For the structure of the metadata files, head over to the Metadata Standard page in Enjin Documentation: https://docs.enjin.io/docs/metadata-standard
- Prepare one metadata .json file for the collection metadata. It’s name must be structured as follows:
<Collection ID>.json
. - Inside the file, Insert the name, description, and any other attribute you’d like, following the Metadata Standard.
- For the media, insert the url of the collection media file uploaded in Step 1: Hosting the media files.
- Since we used IPFS in this example, the url is as follows:
ipfs://<CID FROM STEP 1>/<File Name>.<File Extension>
- Follow the steps 1-4 for each of the tokens metadata .json files, with the following name structure:
<Collection ID>-<Token ID>.json
- Move all of the prepared .json files into a single folder (including the one for the collection)
- In Pinata.cloud, click on the "Upload" button at the top right corner, followed by "Folder"
- Select the folder you've prepared in step #6 to upload it.
- Once the metadata .json files done uploading, copy the “CID” and save it for the next step.
Step 3: Updating the collection uri
Now all that’s left is updating the collection uri, so the collection and all tokens within it, will use the metadata we’ve uploaded in the last step, in a dynamic way.
To do that, follow the same exact steps from the How to update the collection uri attribute, but for the uri attribute, insert the uri of the json files hosted from the previous step.
Since we used IPFS in this example, the uri is as follows: ipfs://<CID FROM STEP 2>/{id}.json
Example: ipfs://bafybeibbu7m12345678123456781234567812345678/{id}.json
*Please note, the {id} is not a placeholder, do not replace the {id} with an actual id, leave it as is.
Once the collection uri is updated on-chain, when fetching tokens metadata, the collection dynamic metadata will be used for all of the tokens in the collection that has no URI attribute.
Converting to the New Token ID Structure
If your collections and tokens were migrated from Ethereum or JumpNet, and you were saving the metadata dynamically using the {id} keyword, then your metadata file names were using the old token ID structure.
In the new ecosystem, we are using a different token ID structure.
Here are the steps to convert from the old token ID structure to the new:
1. Identify the collection ID of the replicated collection on Enjin Blockchain (For this example, we will be using "2000")
2. Host a file with the name <Collection ID>.json
with the collection metadata, specifically.
In our example, the collection ID is 2000
, so we host the collection metadata at https://example.com/metadata/2000.json
3. Identify the old token's metadata .json file name in your old website/CDN (for this example, lets use this one: "70800000000000af000000000000000000000000000000000000000000000005.json") and remove the 32 "0" digits between the 17th position and the 48th position (including)
4. If the old file name was "70800000000000af000000000000000000000000000000000000000000000005.json", you would be left with "70800000000000af0000000000000005.json".
5. Remove the ".json" from the end, and you should now be left with a 32 hexadecimal characters (128 bits).
6. Convert that hexadecimal number to decimal. For example, using this tool, "70800000000000af0000000000000005" in hexadecimal converts to "149538149525803038929858507180710297605" in decimal.
7. Add the .json back in the end of the decimal number, and that's your new file name.
8. Repeat steps 3-7 for all of the tokens.
9. Once all of the token's metadata .json file names are using the new token ID structure, upload them to your website/CDN at https://example.com/metadata/
10. Following the steps in this section: Updating the collection uri, update the uri
of the collection to the path used in the previous step, and append {id}.json
to it.
Example: https://example.com/metadata/{id}.json
.
Comments
0 comments
Please sign in to leave a comment.