Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Transformer #834

Closed
zomglings opened this issue Jul 6, 2023 · 2 comments
Closed

Metadata Transformer #834

zomglings opened this issue Jul 6, 2023 · 2 comments

Comments

@zomglings
Copy link
Contributor

zomglings commented Jul 6, 2023

Almost every NFT includes metadata accessible through the tokenUri view method, and the metadata looks like this:

{
  "description": "Dwarf hammer throwing champion.",
  "image": "https://static.greatwyrm.xyz/act1/characters/5p0rt5BEArD.png", 
  "name": "5p0rt5BEArD",
  "attributes": [ ]
}

The attributes array often contains traits of the character.

The problem this setup is that the information contained in this metadata is not available on-chain.

The whole point of our work is to build on-chain games, which is why we have created things like the Inventory contract to represent attributes and items associated with an NFT in an on-chain registry.

That said, our contracts are not meant to be consumed only on-chain. We should make it easy for off-chain clients to read information related to our smart contract.

The Metadata Transformer is a server which will take the base metadata for an NFT (as returned by the tokenUri method on its ERC721 smart contract), modify the metadata JSON using on-chain data (such as what items are equipped in the inventory), and return this modified JSON as a response.

For example, if the character above (5p0rt5BEArD) had a hammer equipped in its weapon slot on an Inventory contract, the Metadata Transformer would transform the above metadata into:

{
  "description": "Dwarf hammer throwing champion.",
  "image": "https://static.greatwyrm.xyz/act1/characters/5p0rt5BEArD.png", 
  "name": "5p0rt5BEArD",
  "attributes": [
    "weapon": "Hammer"
  ]
}

This would be done dynamically at the time that metadata was requested from the Transformer based on the current state of the blockchain.

How do players interact with the Metadata Transformer?

Any user can make a request to the Transformer of the following form:

curl -X GET "https://api.moonstream.to/metadata?chain_id=1&contract_address=0x521f9C7505005CFA19A8E5786a9c3c9c9F5e6f42&token_id=5"

If this (chain_id, contract_address) pair has transformation logic registered on the Metadata transformer, it is applied, otherwise, the Metadata Transformer simply returns the tokens metadata URI as it is defined on the contract.

Why use the Metadata Transformer?

The Transformer would allow any game client to define modifications to an NFT collection's core metadata for the purposes of its consumption.

For example, a game developer could permissionlessly build a game for an NFT collection like Bored Apes, deploy a non-canonical Inventory contract for the collection, and transform the Bored Apes metadata to add in the equipped items on their non-canonical inventory for off-chain consumption.

Transformations do not need to only apply to textual attributes of the metadata json. For example, one could write a transformation that loaded the image from an NFT's image_url, converted it into an SVG, added layers onto it, and then returned a data URI for the new image to be served to clients consuming that transformation.

The metadata transformer makes it easier for games to move their metadata on-chain using tools like the Inventory contract by making it easy for this on-chain metadata to be consumed off-chain in the same way that all metadata is currently consumed off-chain.

@zomglings
Copy link
Contributor Author

zomglings commented Jul 6, 2023

This fits in well with Ethereal NFT ERC721 relayers, as well.

Each ERC721 relayer would be a natural client of this service, with the Ethereal NFT metadata URI being the Metadata Transformer URI corresponding to the source collection.

@zomglings
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant