Token metadata
INFO
Token metadata should not be confused with contract metadata.
Introduction
Token metadata describe one token (e.g. name, thumbnail...) of an FA2 contract. It provides information that is not directly used for a contract's operation. If an FA2 contract contains 150 NFTs, it will contain 150 token metadata map.
Token metadata are stored in an FA2 contract or in a JSON file stored outside of the blockchain and referenced in the contract.
If you store token metadata outside of the blockchain you'll have to upload them by yourself. We provide some explanations on how to do it.
Usage
Token-specific metadata is stored/presented as a Michelson value of type sp.map[sp.string, sp.bytes]
.
A few of the keys are reserved and predefined by TZIP-12:
""
(empty-string): should correspond to a URI schemes which points to a JSON representation of the token metadata."name"
: should be a UTF-8 string giving a “display name” to the token."symbol"
: should be a UTF-8 string for the short identifier of the token (e.g. XTZ, EUR, …)."decimals"
: should be an integer (converted to a UTF-8 string in decimal) which defines the position of the decimal point in token balances for display purposes.
The library gives an helper: make_metadata
(only available outside the contract) that prepares the sp.map[sp.string, sp.bytes]
.
Example:
example_md = fa2.make_metadata(
decimals=0,
name="Example FA2",
symbol="DFA2")
If you need more values in the metadata, you can create your own map by hands. The previous example is equivalent to:
def bytes_of_string(s):
return sp.bytes("0x" + s.encode('utf-8').hex())
{
"decimals": bytes_of_string("%d" % 0),
"name": bytes_of_string("Example FA2"),
"symbol" bytes_of_string("DFA2")
}
Advanced media
When using NFT you often want to attach an image, a list of author and a lot of information about your token.
The corresponding keys and values are described in TZIP-16. As the content start being big, the convenient way is to add all inside a JSON file, upload it on IPFS and reference it inside the map using URI schemes.