Zilliqa / ZRC

Zilliqa Reference Contracts
MIT License
40 stars 57 forks source link

feat(zrc6): support use cases with metadata URIs with different base URIs #119

Closed ghost closed 2 years ago

ghost commented 2 years ago

Description

This PR supports special use cases with decentralized metadata URIs in ZRC-6.

markdown

References:

RatulSaha commented 2 years ago

@noel-yoo should not there be a MintWithUri transition as well?

ghost commented 2 years ago

@RatulSaha I initially thought a batch operation is enough for a fallback for dynamic or randomized minting with decentalized URIs. We want to keep the standard very minimal if possible.

However, because of the clear event log and the gas saving I included MintWithURI.

Regarding the gas saving, BatchMintWithURIs for a single token costs 559 while MintWithURI would cost 541 (-3.32%).

ghost commented 2 years ago

The solution should be consistent and minimal without creating additional complexity if possible.

The initial approach was having a minimal fallback. But It will make this standard inconsistent and more complex to have BatchMintWithURIs (and MintWithURI) as there will be 3 (or 4) transitions for minting.

Considering this use case https://blog.chain.link/build-deploy-and-sell-your-own-dynamic-nft, the standard needs to be more flexible for token URIs such that it can support dynamic or randomized minting.

Therefore, I've changed the Mint and BatchMint to take the token_uri parameter where token_uri can be empty string.

If you want to use the concatenated URI to save gas cost, pass an empty string for token URI when minting. In this case, the token_uri field doesn't get mutated. Also, you need to initialize base_uri when contract is created.

If you need dynamic or randomized minting with decentalized URIs, pass a specific token URI per token when minting.

RatulSaha commented 2 years ago

For anyone coming later (and maybe hint at this at the standard, @noel-yoo) — this approach also works for hybrid use case. In the same contract, some tokens can be supplied with a token URI, while others have a base URI. This is not exactly recommended for standard use cases, but since the token URI takes precedence over the base URI per token, this is possible for those who may want to.

hatzz commented 2 years ago

This makes me a bit confused, Is it still required to have a base_uri that returns the correct metadata for that nft or are you allowed to have a token_uri which takes presedence over ?

Is this only to be compatible with ERC721?

If I want to fetch metadata am I supposed to have to fetch both base_uri and token_uri substate?

ghost commented 2 years ago

@Hatzz

Each token can use either it's own specific token URI or <base_uri><token_id>.

Case 1: Every token uses <base_uri><token_id> as token URI

This case, the tokens are minted without token URI by Mint or BatchMint. Therefore, there is no specific URI in token_uris field. token_uris field can is an empty map since every token uses <base_uri><token_id>.

e.g. The base URI: https://creatures-api.zilliqa.com/api/creature/ token URIs:

Case 2: Every token has its own token URI and doesn't use <base_uri><token_id> as token URI.

This case, the tokens are minted with token URI by Mint or BatchMint. Therefore, there are specific URIs in token_uris field. The base_uri field can be an empty string since every token has its own token URI.

e.g. The base URI: empty string token URIs:

Case 3: Some tokens use <base_uri><token_id> as token URI and some have their own token URI.

This case is a mix of case 1 and case 2. Both base_uri and token_uris field are used. base_uri shouldn't an empty string and token_uris shouldn't be an empty map.

The base URI: https://creatures-api.zilliqa.com/api/creature/ token URIs:

How to get a token URI for a token

To get a token URI for a token, do:

  1. Fetch a specific token URI first. If a specific token URI exists, use it as the token URI.
  2. If there is no specific token URI for a token, fetch the base URI to use <base_uri><token_id>.
bb111189 commented 2 years ago

@noel-yoo can you check https://github.com/Zilliqa/ZRC/pull/119/commits/3842e1e63c7da990a53a6e374e344b940a1affdb

ghost commented 2 years ago

rebase

hatzz commented 2 years ago

@noel-yoo Thanks for the reply! Do you think this should be written in the documentation somewhere maybe?

ghost commented 2 years ago

I have updated the field description for base_uri and token_uris.