ecadlabs / taquito

A library for building dApps on the Tezos Blockchain - JavaScript / TypeScript
https://taquito.io
Apache License 2.0
298 stars 116 forks source link

[TZIP-012] Fail to parse Token Metadata located in tezos-storage URI #2120

Closed pewulfman closed 1 year ago

pewulfman commented 1 year ago

Description As a core developer at LigoLang, I have been extending our FA contracts in the database to include token_metadata. The implementation is there : https://github.com/pewulfman/Tezos-TZIP-implementation/blob/main/TZIP-12%20(FA2)/standard_contract/FA2_multi_asset.mligo#L113 And the contract was published on ghostnet at address KT1FzbvvG8Y6GE4VU7iyGqT7M5TLWzKkDC5X I experimented with both possibility for metadata as defined in TZIP-012 : https://github.com/pewulfman/Tezos-TZIP-implementation/blob/main/TZIP-12%20(FA2)/standard_contract/FA2_multi_asset.mligo#L113 I believe the metadata are written correctly and are parsed by both Better-call.dev and TzKT.io

The alternative using a direct map ["name";"symbol";"decimals"] works well. (Token 1 and 3). However when using c.tzip12().getTokenMetadata(0) taquito returns The URI { "name" : "Wulfy FA2 multi asset 0", "symbol" : "WMA0", "decimal" : "3", } is present in the token metadata, but is invalid. or Uncaught (in promise) InvalidTokenMetadata: Non-compliance with the TZIP-012 standard. The required propertydecimalsis missing.

Looking at the logs. It seem that taquito does resolve the URL, convert from bytes to string. And tries to access the field "decimals" on the strings. I believe it should first parse the string to JSON before trying to access any fields

Steps To Reproduce Steps to reproduce the behavior: Fetch contract on ghostnet at address : KT1FzbvvG8Y6GE4VU7iyGqT7M5TLWzKkDC5X

const c = Tezos.contract.at("KT1FzbvvG8Y6GE4VU7iyGqT7M5TLWzKkDC5X")
c.tzip12().getTokenMetadata(0)

Expected behavior The function is supposed to parse the metadata at tezos-storage:data, and not fails

Screenshots Success for token_id 1 : image (1)

Some info on what is parse for token_id 0: image (2) image (3) image (4)

Desktop (please complete the following information):

Additional context My collegue posted here : https://github.com/ecadlabs/taquito/issues/503#issuecomment-1315104552

dsawali commented 1 year ago

Hey team! Please add your planning poker estimate with Zenhub @hui-an-yang @roxaneletourneau @zainen

dsawali commented 1 year ago

Hello @pewulfman, thanks for writing this ticket. I looked a bit further into your contract at KT1FzbvvG8Y6GE4VU7iyGqT7M5TLWzKkDC5X.

And I found a few things that explain why parsing failed in Taquito. Taquito follows the Tzip12 format as stated here https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md#token-metadata.

Taquito expects what we call a MichelsonMap object, and specifically for token metadata, this form:

{
  name: "",
  symbol: "",
  decimals: "",
}

The error that you are receiving, as you have already stated above, is due to Taquito not being able to find the decimals key in your object (specifically Token 0 and 2).

And looking into the contract in tzkt, Token 0 metadata looks like this: image

While we can physically see the Tzip12 metadata format correctly nested inside data, it's not expected for Taquito to receive extended forms of the metadata, or do any parsing for non-standard forms of it. The correct example of metadata would be in the direct map as you have written for Token 1 and 3.

Having said that, I don't think we can support the format you are using. While it is reasonable request, we would like to keep Taquito to be as in-line and compliant with Tzip12 as possible. Please let us know if you have any other concerns.

Innkst commented 1 year ago

We have suggested an approach that Taquito supports and that is compliant with tzip-12. Closing