Jan 23, 2024

Metadata in Chainsight, Describes providing static data for users by metadata.

by Megared

Now, we are starting a new series of articles on Chainsight innovations related to canisters. In this article, we will introduce the management of static data for users using Metadata.

Information for users in blockchain contracts is often stored off-chain. Contraptions may be used in the preservation area, but consider keeping them to a minimum. This is because the size of the logic/data embedded in the contract directly affects the cost to the user.

What is Metadata in Internet Computer?

To explain this point, I would like to start with the basics of Internet Computer for beginners, as some of you may already know. In general, a contract in the blockchain is called a canister in Internet Computer. The canister installs and runs Web Assembly (WASM) modules generated from code in Internet Computer's proprietary language Motoko, as well as general-purpose languages such as Rust and Python. The original source code of the WASM module used here is assembled with contract code for logic and interface declarations, state generation, etc.

The Web Assembly binary format developed by the World Wide Web Consortium (W3C) includes a Custom Section. This is a section that is intended to be used for debugging or extensions for 3rd parties and holds arbitrary byte data and a name identifying its Custom Section.

https://webassembly.github.io/spec/core/binary/modules.html#custom-section

Internet Computer provides metadata using the Custom Section of WASM as described above. It targets the Custom Section named icp:public <name> or icp:private <name> and incorporates it as metadata in the canister.

https://internetcomputer.org/docs/current/references/ic-interface-spec#state-tree-canister-information

chainsight_deepdive_into_showcase-metadata.png

Let's take a look at the actual Metadata. Metadata in deployed canisters can be obtained from the API in the aforementioned link. If there is a WASM module, it can be read by tools that can interpret WASM binary, and this time we will use dfinity's tool, ic-wasm.

https://github.com/dfinity/ic-wasm

You can get a list of the configured Metadata with the metadata command, and you can view the data in that section with metadata <name>.

Run it for the WASM module…

% ic-wasm example.wasm metadata
icp:public candid:args
icp:public candid:service

% ic-wasm example.wasm metadata candid:service
service : {
  greet : (text) -> (text) query;
}

Modules built with dfx are given icp:public candid:service by default, and the section contains the candid interface for that module. Metadata can be utilized in this way.

Metadata in Chainsight Components

Chainsight uses this Metadata to provide static information for users. Although there are general Pros/Cons as described in the introduction, there is a disadvantage that including static information in the canister storage or adding a function to return it to the canister makes the canister logic code more complex, which is why Chainsight Component utilizes Metadata.

Chainsight assigns the followings Metadata to the current Component. The format is icp:public chainsight:<metadata_label>, except for the metadata_label, which is a common prefix. I will explain each item. The example uses the Snapshot Indexer for the U.S. Treasury Yield Curve.

label

Label for Component. Used for naming.

ex: US Treasury Yield Curve from Investing.com

component_type

Component types within Chainsight support.

ex: snapshot_indexer_https

description

A descriptive text for the Component. This is used to explain how it is designed and works.

ex: Collect US Treasury Yield Curve from Investing.com, data with maturities ranging from 1 month to 30 years are obtained.

tags

Tagging for Component. Arbitrary tags can be set using strings. These can be used to narrow down the total amount of Components, for example.

ex: ["Yield Curve","Bonds","US Treasury"]

We also use other Metadata depending on the type of Component.

% ic-wasm component.wasm metadata
icp:public chainsight:label
icp:public chainsight:component_type
icp:public chainsight:description
icp:public chainsight:tags
icp:public chainsight:sources
icp:public chainsight:intervalSec

The Chainsight Platform also leverages this Metadata to provide a convenient viewer for the Component in the Chainsight UI, the front-end for Chainsight users.

https://beta.chainsight.network/

Chainsight's unique Metadata is used to display basic information and search by tags.

Untitled.png Untitled.png

We have introduced one of Chainsight's unique innovations that take advantage of Internet computers. We are also continuing our series of deep dives into Showcase.

Follow us on Twitter and Medium for updates! We look forward to seeing you there!

Written by Megared@Chainsight