Skip to main content

Token medatada

Implements TZIP-21 norm for token metadata.

Repository


Author


Templates

Code

info

It is required to copy this code in the created contract to benefit from the token metadata pattern.

/* TOKEN METADATA ------------------------------------------------------------ */

constant TOKEN_ID : nat = 0

asset token_metadata to big_map {
ftoken_metadata : nat;
token_id : nat;
token_info : map<string, bytes>;
} initialized with {
{TOKEN_ID; TOKEN_ID; [("", metadata_coin)]}
}

entry set_token_metadata (tid : nat, tdata: map<string, bytes>) {
called by owner
require { tmd_r1: is_not_paused() }
effect {
token_metadata.add_update(tid, { token_id = tid; token_info = tdata });
}
}

asset nat map string bytes entry nat map string bytes called by require is_not_paused effect add_update

Storage

token_metadata

When dealing with FA 1.2, the token_metadata map is initialized with the hex-encoded ipfs URI of the token metadata file (see examples below):

Code


constant TOKEN_ID : nat = 0

asset token_metadata to big_map {
ftoken_metadata : nat;
token_id : nat;
token_info : map<string, bytes>;
} initialized with {
{TOKEN_ID; TOKEN_ID; [("", metadata_coin)]}
}

asset nat map string bytes

Type


Related

Entrypoints

set_token_metadata(tid, tdata)

Code


entry set_token_metadata (tid : nat, tdata: map<string, bytes>) {
called by owner
require { tmd_r1: is_not_paused() }
effect {
token_metadata.add_update(itokenid, { tid = tid; token_info = tdata });
}
}

entry nat map string bytes called by require is_not_paused effect add_update

Parameters


tid :

Token id


Token data

Fails with

"INVALID_CALLER"

When caller is not owner


"CONTRACT_PAUSED"

When contract is paused.


Related

Examples

Fongible token

{
"symbol": "MyC",
"name": "My Coin",
"decimals": 6,
"description": "An example of My Coin",
"thumbnailUri": "ipfs://QmPibs6dkHjoJAkE9BiPURCnCBfphaT7P6y5MZ4eTYtyS9",
"isTransferable": true,
"isBooleanAmount": false,
"shouldPreferSymbol": false
}

NFT

{
"symbol": "ARC",
"name": "MyNFT #1",
"decimals": 0,
"description": "a description of NFT",
"artifactUri": "ipfs://Qmb7sj8KYoUCJ29DT2qbKxHV5ubaDBRRoDwAPPZakpvn4Y",
"displayUri": "ipfs://Qmb7sj8KYoUCJ29DT2qbKxHV5ubaDBRRoDwAPPZakpvn4Y",
"thumbnailUri": "ipfs://Qmb7sj8KYoUCJ29DT2qbKxHV5ubaDBRRoDwAPPZakpvn4Y",
"isTransferable": true,
"isBooleanAmount": true,
"shouldPreferSymbol": false,
"tags": ["NFT"],
"creators": ["tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg"],
"attributes": [
{
"name": "color",
"value": "grey"
}
],
"royalties": {
"decimals": 3,
"shares": {
"tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg": 75
}
}
}