Asset and metadata are used when you mint Klaytn's KIP-17>) Tokens (NFTs), KIP-37>) Tokens (MTs).

This tutorial explains how to upload assets and metadata using the Metadata API.

Asset Upload

An asset refers to an image or a video file of an NFT or MT and is stored in the token information in the form of files (jpg, gif, png, etc.). When you mint an NFT or MT, you first have to upload the asset and include the returned asset URI in the metadata when minting the token. It is stored in JSON format.

API Request

You can upload an asset by sending a request to the endpoint POST/v1/metadata/asset of the Metadata API.

The cURL code for uploading assets is as follows.

Copy
Copied
curl --location --request POST 'https://metadata-api.klaytnapi.com/v1/metadata/asset' \
--header 'x-chain-id: 8217' \
--header 'Authorization: Basic S0FTS0U0Mjc5Q01VMVhLVDg1UTRBVkRBOlFEMENMam5XRW94TzZfQ3pYLV9oLWRrQkZnMDVxR1FnbWlYcDAwVno=' \
--form 'file=@"/Users/usernamed/Documents/files/1kbfile.jpg"'

Each part is explained as follows:

  • POST ' https://metadata-api.klaytnapi.com/v1/metadata/asset' : Method type (POST) and an endpoint to which the request will be sent.
  • x-chain-ID: Metadata API requires x-chain-id header value; 1001 (Baobab) or 8217 (Cypress).
  • Authorization: KAS uses Basic HTTP Auth. All requests must have a correct Authorization header and a KAS user can create the credentials to be used for Basic Auth by using username as access key ID and password as secret access key .
  • Form: The location of the file to be uploaded. The file size is limited to 10MB.
info

KAS does not verify the validity of the URL that can access the asset, so you have to check it yourself.

API Response

When you upload an asset using curl, it returns as follows:

Copy
Copied
{
  "contentType": "image/png",
  "filename": "4a85e6be-3215-93e6-d8a9-3a7d633584e7.png",
  "uri": "https://metadata-store.klaytnapi.com/e2d83fbb-c123-811c-d5f3-69132v482c51/4a85e6be-3215-93e6-d8a9-3a7d633584e7.png"
}
  • File Name: Returns a unique identification value automatically assigned to an asset as a file name.
  • Content Type: Indicates the request format. The above example is a png image file.
  • URI: Externally accessible URI where metadata is stored. It is in the format https://example.com/{storage-ID}/{asset-ID}.png . Storage ID is a unique identification value given to each user, and Asset ID is an identification value automatically assigned to each asset.

Access the returned URI and check if the correct asset has been uploaded.

Metadata Upload

Metadata originally refers to "data of data". In the context of NFTs or MTs, it refers to the properties (name, description, image URL etc.) of the tokens. It is stored in JSON format.

API Request

You can upload metadata by sending a request to the endpoint POST/v1/metadata of the Metadata API.

Copy
Copied
{
    "metadata": {
        "name": "Kitty Heaven NFT",
        "description": "This is a sample description",
        "image": "https://metadata-store.klaytnapi.com/e2d83vdb-c108-823c-d5f3-69vdf2d871c51/4a85e6be-3215-93e6-d8a9-3a7d633584e7.png"
},
    "filename": "haha.json"
}

Each part is explained as follows:

  • Name: The token name.
  • Description: The token description.
  • Image: Externally accessible URI where the token image is stored.
  • File Name: Optional. You can specify the returned file name as you want with the extension, .json .

API Response

Copy
Copied
{
  "filename": "haha.json",
  "contentType": "application/json",
  "uri": "https://metadata-store.klaytnapi.com/e2d83vdb-c108-823c-d5f3-69vdf2d871c51/haha.json"
}
  • File Name: Returns a unique identification value automatically assigned as a file name.
  • Content Type: Indicates the request format. The above example is a JSON format.
  • URI: Externally accessible URI where metadata is stored. It is in the format https://example.com/{storage-ID}/{file-name }. Storage ID is a unique identification value given to each user.

Access the returned URI and check if the correct metadata has been uploaded.

For more details regarding this API, please refer to here. For any inquiries regarding this document or KAS in general, please visit KAS Developers Forum.