Are there any downsides to how I'm declaring the token_metadata in the @offchain_view below? Loading the data from storage appears to work as expected when testing it on tzcomet and BCD, though I just want to confirm this approach looks good.

I want to build out the attributes JSON array to be compliant with the tzip-21 interface, but doing the string manipulation for that is going to be a huge pain. Is there a utility I could import for this? Are there any code reference for a tzip-21 token_metadata offchain_view that have the attributes map? Thanks in advance.

    @sp.offchain_view(pure = True)
    def token_metadata(self, tok):
         sp.set_type(tok, sp.TNat)

         sp.result(sp.record(token_id=tok, token_info={
            "name": self.data.token_metadata[tok].token_info["name"],
            "symbol": self.data.token_metadata[tok].token_info["symbol"],
            "decimals": self.data.token_metadata[tok].token_info["decimals"],
            "description": Utils.Bytes.of_string("A unique TezosAsset NFT representing someone's purchased asset."),
            "isBooleanAmount": Utils.Bytes.of_string("true"),
            "artifactUri": Utils.Bytes.of_string(string_concat("http://abcd.xyz/asset/", string_of_nat(self.data.arr[tok].x))),
            # TODO: encode x,y under JSON attributes array
            "x": Utils.Bytes.of_string(self.string_of_nat(self.data.arr[tok].x)),
            "y": Utils.Bytes.of_string(self.string_of_nat(self.data.arr[tok].y))
  • is the dynamic artifact uri the reason you're wanting to do this? i would love to be able to serve dynamic tzip-21 from a contract, did you manage to get this working correctly? if so can you answer your own question here?
    – 0x10
    May 6 at 3:28

1 Answer 1


Generally the tzip-21 are implemented as JSON document on ipfs and the CID (the URI of the content on IPFS) are save in the token_info field as a bytes. Your implementation seems a little bit unusual or better, because is not the most used method, is possible that some wallet or Explorer could not show it correctly, moreover is a lot of field to put into a BigMap and process in a transaction with a poor user Experience, the "best" and cheapest way is to upload the JSON tzip-21 on IPFS and then pass only the response CID to the contract, but is a your Design decision.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.