Skip to main content

Adding Metadata

Adding Metadata

to a token enables games and apps to import detailed information and showcase your token's data. Usually, digital assets are identified just by its Token ID. Metadata adds extra details to these assets, giving them properties such as a title, a narrative, and visuals.

What you'll need:
  • Some Enjin Coin on Enjin Matrixchain to pay for Transaction Fees and metadata Storage Deposits.
    You can obtain cENJ (Canary ENJ) for testing from the Canary faucet.
  • An Enjin Platform Account.
  • A Collection and a Token to add metadata to.
  • Follow our Best Practices for Collection/Token Metadata.

You can even use metadata to attach gifs, videos, and 3D models to your token. This data can be stored both on-chain and off-chain to allow users and other supported platforms to access the information.

When storing data on-chain, metadata can be defined as attributes such as name, description, fallback image, and any other attribute you choose. However, if the data is stored off-chain, it should always reference a centralized public repository through a .json file.

Metadata Storage

There are three main ways to store metadata for your tokens:

  1. On-Chain Storage: Attributes

    • Storing metadata directly on the blockchain is known as on-chain storage.
    • It's immutable and highly secure since it's protected by the Enjin Blockchain's decentralized nature.
    • On-chain storage can cost a small fee at the time of mint and has slight limitations in terms of space, making it suitable for smaller, permanent files.
  2. Off-Chain Storage: JSON

    • This means the metadata is stored outside the blockchain on a separate server or database.
    • It's often accessible through a URL, typically pointing to a JSON file containing the asset's information.
    • Off-chain storage is cheaper and more flexible for large or frequently updated data, but it relies on external servers' availability and security.
  3. InterPlanetary File System (IPFS): JSON

    • IPFS is a decentralized storage solution that distributes file storage across a network of computers.
    • It allows metadata to be stored off the main blockchain but in a way that's still decentralized, tamper-proof, and permanent.
    • IPFS assigns a unique hash to each file. When you store metadata on IPFS, you link to it using this hash, ensuring the data remains unchanged.

Each option has trade-offs between cost, reliability, and security, and the choice depends on the specific needs and goals of the digital asset being created.

Attributes: OnChain Metadata

You can assign multiple on-chain attributes to a token simultaneously, which allows you to define the metadata of the token.

Some commonly recognized attributes, following the Universal Metadata Standard, include:

  • name: The title of the token.
  • description: A brief explanation or description of the token.
  • media: A token image, GIF, or MP4 to represent the token.
  • URI: The web address (URL) where the JSON file containing the token's off-chain or IPFS metadata is hosted.
Attributes for Collections and Tokens are very similar.

The process of adding attributes is similar for both collections and tokens.
While this tutorial guides you through adding an attribute to a token, you can follow the same steps to add attributes to a collection.
Simply navigate to the corresponding menu for collections instead of tokens.

Important: Attribute keys are case sensitive.

Ensure you use the correct casing when defining attributes to avoid errors.

There are two ways to add metadata:

  1. Using the Enjin Dashboard
  2. Using the GraphQL API & SDKs

Option A. Using the Enjin Dashboard

In the Platform menu, navigate to "Tokens".
Locate the token you wish to add / edit attributes for, click the 3 vertical dots () to it's right, then click the "Attributes" button.

Adding Metadata

Need to add multiple attributes for a token?

Click on the "Batch" button, followed by "Batch SetAttribute".

To add / edit an attribute, select the "Set" option, type in the "Key" that you wish to add / edit, and it's "Value" in the corresponding text fields.

Once you're satisfied with the options, click on the "Set Attribute" button at the bottom right corner to create the request.

Set Attribute form

The Transaction Request will then appear in the "Transactions" menu.

Set Attribute Banner

Pending Set Attribute Banner

Since this request requires a Transaction

, it'll need to be signed with your Wallet.

  • If a Wallet Daemon is running and configured, the transaction request will be signed automatically.
  • If a wallet is connected such as the Enjin Wallet or Polkadot.js, the transaction must be signed manually by clicking the "Sign" button and approving the signature request in your wallet.

Option B. Using the Enjin API & SDKs

The BatchSetAttribute mutation allows you to efficiently set or update multiple attributes for a specific token within a collection in a single blockchain transaction. Attributes represent various properties, characteristics, or metadata associated with a token.

mutation BatchSetAttribute {
BatchSetAttribute(
collectionId: 36105 # Specify the collection ID
tokenId: {integer: 0 } #Specify the token ID. If you wish to add collection metadata, omit this line entirely.
attributes: [
{
key: "name" #Provide an attribute name
value: "Chronicles of the Celestium" #Provide an attribute value
},
{
key: "description" #Provide an attribute name
value: "An epic saga where players assume the roles of intrepid tradesmiths, shaping destinies with fire and will across the star-woven expanses of the multiverse." #Provide an attribute value
},
{
key: "uri" #Provide an attribute name
value: "https://yourhost/metadata.json" #Provide an attribute value
}
]
) {
id
method
state
}
}

A WebSocket event will also be fired so you can pick up the changes in real-time by listening to the app channel on the WebSocket.

JSON File: Off-Chain & IPFS Metadata

A JSON file can be used to provide comprehensive information about the asset, including its description, visual representation, multimedia attachments, external references, categorization, associated files, and specific attributes.

Take a look at this simple JSON schema (following the Universal Metadata Standard) to learn how to properly format the off-chain metadata for your NFT.

{
"name": "Starforged Cleaver",
"description": "A blade smithed from cosmic steel, its edge sharp enough to slice through the fabric of reality itself.",
"external_url": "https://enjin.io",
"fallback_image": "https://yourhost/image.jpg",
"media": [
{
"type": "image/png",
"url": "https://yourhost/image.jpg"
}
],
"attributes": {
"Strength": {
"value": "800"
}
}
}

Take note of these data points:

  • description: This field provides a human-readable description of the asset. It's a text description that helps users understand the nature or significance of the asset.

  • media: The media field contains a URL pointing to an image representation of the asset. It supports PNG, GIF, and JPG file formats.

  • external_url: The "external_url" field is a URL pointing to an external application or website where users can view additional information or interact with the asset.

  • attributes: This is an object array where each object should contain an title and value fields. The attribute title defines the type of trait or attribute associated with the asset, while value can be a string or a number, representing the value of that trait or attribute.

You can also host your JSON files on IPFS, to make your metadata more immutable.

Explore More Arguments

For a comprehensive view of all available arguments for queries and mutations, please refer to our API Reference. This resource will guide you on how to use the GraphiQL Playground to explore the full structure and functionality of our API.

For instance, you'll find settings such as continueOnFailure to skip data that would cause the whole batch to fail, or the ability to sign using a managed wallet with the signingAccount argument.

What's next?

To mint some token supply, head to the Minting Tokens tutorial.