Core Module

This module has main functions, which are used to manage NFT schema, NFT Data, and Actions. We can use these 3 data models to provide mutable metadata on the NFT Chain.

Metadata Schema

In order to work with metadata dynamically , we need to define basic information of the NFT from origin chain ( Ethereum, Klaytn or EVM chain ), attributes which will be maintained on NFT Data chain and also actions that process those attributes.

Name
Data Type
Description

code

string

unique code to identify your NFT.

name

string

Name of the NFT

owner

string

Cosmos-based address who create the this schema

system_actioners

array

Array of addresses that has permission to perform actions

origin_data

object

Information from origin chain

  • origin_base_uri

string

Base URI representing metadata on origin chain

  • uri_retrieval_method

string

Retrieval method of the origin metadata ("base", "token").

  • origin_chain

string

Origin chain which NFT Smart Contract is deployed ( "ethereum" , "klaytn" )

  • origin_contract_address

string

Smart Contract address

  • attribute_overriding

string

When there is an attribute designed to manage on data chain with the same attribute on the origin chain, this indicator will determine which value will be presented from the data chain's metadatabase URI.

  • metadata_format

string

To indicate the format when metadata was presented.

  • origin_attributes

list of attribute definition

list of origin attributes

- name

string

Attribute name

- data_type

string

Data type of attributes. One of number, string, boolean and float

- display_value_field

string

The field name represents the attribute's value when displayed in a marketplace format. For example, "opensea." See the whole example below.

- display_option

object

Attribute format represent attribute data in marketplace format. For example , {

"opensea":

{

"trait_type": "Background L"

}

}

onchain_data

object

Dynamic part of metadata

  • nft_attributes

list of attribute definition

A list of attributes in which every token metadata has the same value can only be changed by the NFT creator, not the token holder. Same structure as attributes in origin part

  • token_attributes

list of attribute definition

A list of metadata attributes is stored on the chain for each token of the NFT. Attribute Definition is the same structure as attributes in the original part

  • actions

list of Action

A list of actions (a logic to update attribute value) pre-designed for users to perform

- name

string

Action name which is used to referred for invoking

- desc

string

A description of the action

- when

string

Conditions to validate to be valid before invoking Action

- then

list of sub-actions

A list of line s of action to make changes on the attribute. For example, if we need to decrease one attribute by 1, the code will be like this -> "meta.SetNumber('percent_discount_10',meta.GetNumber('percent_discount_10') - 1)"

- params

list of object params

A list of parameters of actions. Some action required the parameter to make it able to perform.

To explain easily how we can create the schema, we can use the command line built from CosmosSDK

sixnftd tx nftmngr create-nft-schema --from alice \
    <BASE64 schema>

<BASE64 schema> is the NFT Schema from the above table in JSON encoded by base64.

NFT Data

There are 2 important parts to the NFT Data. One is data from the origin chain and those attributes maintained in Data Chain. See the table below:

Name
Data Type
Description

nft_schema_code

string

Code reference to a unique schema

token_id

string

NFT Token iD

token_owner

string

A Cosmos-based account that owns the token.

origin_image

string

an image URL originally defined

onchain_image

string

As an option, a new image URL in case there is a business case to change an image after some actions

token_uri

string

URI By token, used if present. If not schema's origin_base_uri is used.

origin_attributes

list of attribute value

List of attributes which has the same value as in original metadata. It's read-only and should never be changed after minting is started

onchain_attributes

list of attribute value

List of attributes with a mutable value that can be modified by calling actions.

Available function

Function
Desc

meta.GetImage()

It will find and return onchain_image from nft_metadata, when onchain_image is empty it will return origin_image form nft_metadata instead

meta.SetImage(string)

To set new onchain_image of nft_metadata

meta.GetNumber(attribute_name)

It will return value of attribute type number

meta.GetFloat(attribute_name)

It will return value of attribute type float

meta.GetString(attribute_name)

It will return value of attribute type string

meta.GetBoolean(attribute_name)

It will return value of attribute type boolean

meta.SetString(attribute_name,new_value)

To set new value of attribute type string

meta.SetNumber(attribute_name,new_value)

To set new value of attribute type number

meta.SetFloat(attribute_name,new_value)

To set new value of attribute type float

meta.SetBoolean(attribute_name,new_value)

To set new value of attribute type boolean

meta.ReplaceAllString(string,to_replace,replace_with)

To place string according to regex that we find

meta.SetDisplayArribute(attribute_name,new_value)

To hide/show attribute from marketplace (new_value should be true/false)

meta.TransferNumber(attribute_name,target_id,value)

Transfer attribute type number to target token. Ex: transfer points

meta.{Utils}

Function
Desc

meta.GetBlockHeight()

It will return current blocktime of chain

meta.GetUTCBlockTimestamp(format)

meta.GetBlockTimestampByZone(zone,format)

meta.BlockTimeUTCBefore(target_time,format)

Validate current time is before time of input and its format (return true/false)

meta.BlockTimeUTCAfter(target_time,format)

Validate current time is after time of input and its format (return true/false)

meta.BlockTimeBeforeByZone(target_time,zone,format)

Validate current time is before time of input time, zone and its format (return true/false)

meta.BlockTimeAfterByZone(target_time,zone,format)

Validate current time is after time of input time, zone and its format (return true/false)

Last updated