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)
self.init(
ledger=sp.big_map(ledger, tkey=sp.TNat, tvalue=sp.TAddress),
metadata=sp.set_type_expr(metadata, sp.TBigMap(sp.TString, sp.TBytes)),
last_token_id=sp.nat(len(token_metadata)),
)
Common.__init__(
self,
policy=policy,
metadata_base=metadata_base,
token_metadata=token_metadata,
)
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.
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"},
}
sp.add_compilation_target(
'Simplest NFT Compiled',
FA2.Fa2Nft(
metadata = sp.utils.metadata_of_url("YOUR_JSON_FILE_URI"),
metadata_base = your_custom_metadata
)
)