Metadata
Implements TZIP-16 norm for contract's metadata.
Repository
Author
Norm
Templates
Storage
metadata
The TZIP-16 metadata map is declared with the native with metadata
declaration.
Entrypoints
set_metadata(k, d)
Adds or removes an entry to the metadata
map.
Code
/* METADATA ---------------------------------------------------------------- */
entry set_metadata(k: string, d : option<bytes>) {
called by owner
require { md_r1 : is_not_paused() }
effect {
metadata.update(k, d)
}
}
entry
string
option
bytes
called by
require
effect
metadata
update
Parameters
v
:
option<bytes>
some(v)
associatesv
tok
none
removes entryk
Fails with
"INVALID_CALLER"
caller
is not owner
"CONTRACT_PAUSED"
Related
Example
Below is a typical metadata file:
{
"name": "My Dapp",
"description": "A description of My Dapp",
"version": "1.0",
"license": { "name": "MIT" },
"authors": ["Mysterious team <contact@my_company.com>"],
"homepage": "https://my_dapp.com",
"interfaces": ["TZIP-012", "TZIP-016", "TZIP-017", "TZIP-021"]
}
There are 2 ways to associate this metadata to a contract:
- upload the file to a public storage (typically
IPFS
) and store the URI in the contract'smetadata
map (as the value of key""
) - store metadata fields in the contract's
metadata
map
The association may be done at deployment time with Completium CLI:
Public URI
Thre following command deploys a contract and specifies the IPFS URI:
completium-cli deploy my_dapp.arl --metadata-uri "ipfs://..."
where ...
is replaced by the IPFS hash obtained when uploading to IPFS.
This is the preferred way since indexers will automatically retrieve the metadata from IPFS.
Stored metadata
completium-cli deploy my_dapp.arl --metadata-storage "./my_dapp_metadata.json"
Entrypoint
This can also be done once the contract is deployed with the set_metadata
entrypoint:
completium-cli call my_dapp --entry set_metadata --arg '{ "k": "", "v": "0x697066733a2f2f ..." }'
Note that the URI is sent in bytes format.