Hello I am using the template Fa2NFT library. When we add the compilation target we need to give it a metadata parameter. I am trying to give it a custom metadata but still it is using the default base metadata mentioned in class Common . Could you please point me out the difference of between metadata and metadata_common and how should I set the contract metadata?

Q from Slack.

1 Answer 1


In the constructor of Fa2Nft, it takes both metadata and metadata_base arguments

def __init__(
    self, metadata, token_metadata=[], ledger={}, policy=None, metadata_base=None
    ledger, token_metadata = self.initial_mint(token_metadata, ledger)
        ledger=sp.big_map(ledger, tkey=sp.TNat, tvalue=sp.TAddress),
        metadata=sp.set_type_expr(metadata, sp.TBigMap(sp.TString, sp.TBytes)),

Both metadata and metadata_base have different purposes. When you pass your custom metadata in metadata_base, the IDE will create a JSON for you including all the off-chain views and other information. Then, you need to upload this JSON file somewhere and refer to it in the metadata field.

As it is explained in this documentation here

The command to generate the json file is: self.init_metadata(, <metadata_base>).

It generates a file with the name .

The content can be seen:

  • in the WebIde in the metadata tab of the contract
  • in the files generated by the CLI.

This command is internally called on metadata_base if you pass it. And, it will generate a JSON for you.

The JSON file has to be uploaded somewhere outside the blockchain.

There are two main solutions:

  • uploading the file on IPFS.
  • uploading it on a regular server/service that exposes the file through HTTPS.

enter image description here

After uploading, you'll need to pass that URI as a metadata argument.

import smartpy as sp
FA2 = sp.io.import_script_from_url("https://smartpy.io/templates/fa2_lib.py")

your_custom_metadata = {
    "name": "Simplest NFT",
    "version": "1.0.0",
    "description": "An example metadata_base",
    "interfaces": ["TZIP-012", "TZIP-016"],
    "authors": ["SmartPy <https://smartpy.io/#contact>"],
    "homepage": "https://smartpy.io/ide?template=FA2.py",
    "source": {
        "tools": ["SmartPy"],
        "location": "https://gitlab.com/SmartPy/smartpy/-/raw/master/python/templates/FA2.py",
    "permissions": {"receiver": "owner-no-hook", "sender": "owner-no-hook"},

    'Simplest NFT Compiled',
        metadata = sp.utils.metadata_of_url("YOUR_JSON_FILE_URI"),
        metadata_base = your_custom_metadata

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.