Dynamic Resolver

The DynamicUriResolver

The Resolver analyzes the string passed as uri, and renders it correctly.

For the analysis, it checks:

  • If the passed uri is static (i.e “traditional”) or dynamic.

    • If static, it returns the uri as it was passed, i.e as plainUri.

    • If dynamic, it checks if a Renderer contract was passed.

      • If not, it returns plainUri.

      • If yes, it calls the Renderer’s render function.

        • If render doesn’t work, or if the string can’t be rendered (because it isn’t written correctly, contains errors or for another reason), it returns plainUri.

        • If it does work, the dynamic metadata is rendered correctly.

The only function of the Resolver is the resolve function:

function resolve(address subject, string calldata plainUri, bytes calldata inputData, address caller) external view returns(string memory);

The function’s input parameters are as follows:

  • address subject -> as the resolve function is external, it must be called by an external contract; the address subject is the address of that contract.

  • string calldata plainUri -> this string represents the uri, which can be static or dynamic. If dynamic, it’s an encoded ABI string that contains a specific DynamicUriRenderer contract and an optional payload of bytes.

  • bytes calldata inputData -> This contains encoded parameters in bytes form, which the Renderer can use to show some specific information.

  • address caller -> This is the msg.sender of the function that requires the metadata. For example, you can call the Main Interface to pass the itemId function.

If dynamic uri is passed, it is resolved by the resolve function.

(address renderer, bytes memory rendererData) = abi.decode(plainUri.asBytes(), (address, bytes));

The encoded uri string is decoded, retrieving the Renderer contract address and any additional payload.

This additional rendererData payload parameter must be passed, or passed as 0x.

The resolve function calls the render function of the passed Renderer address:

try IDynamicUriRenderer(renderer).render(subject, plainUri, inputData, caller, rendererData) returns (string memory renderedUri)

The Renderer contract will try to render the metadata.

If it succeeds, it will return the renderedUri.

Last updated