1

I'm trying to set metadata for a collection of the NFTS pallet. I'm doing this from a custom pallet.

To structure the metadata I'm using this guide: https://wiki.polkadot.network/docs/learn-nft-pallets

The guide stipulates that I should construct metadata as json with the following structure:

{
    "name":"Your Collection Name",
    "description":"Collection's Description",
    "image":"Your Collection CID"
}

How can I do this when using T::Nfts::set_collection_metadata(None, &T::ExperienceNFTCollectionId::get(), &metadata)?;?

I have tried many ways, but they all result in an IncorrectMetadata error. To be specific I tried:

  • Creating a struct which I then SCALE encode. My believe is that this should be the right way, since it would be inefficient to store json bytes.
  • Use a raw byte array of the json string (very inefficient)
  • Use a SCALE encoded json string

Finally, I also replaced set_collection_metadata with setting each field individually with set_collection_attribute, but even that results in the aforementioned error for the image attribute.

T::Nfts::set_collection_attribute(&T::ExperienceNFTCollectionId::get(), b"name", b"Experience credentials")?;
T::Nfts::set_collection_attribute(&T::ExperienceNFTCollectionId::get(), b"description", b"Experience credentials")?;
T::Nfts::set_collection_attribute(&T::ExperienceNFTCollectionId::get(), b"image", b"https://cdn.pixabay.com/photo/2017/11/10/01/38/sand-2935107_960_720.jpg")?;

The guide uses IPFS, but I can hardly imagine that I'm obliged to use IPFS URLs for the image and that the problem if caused by using a random image URL for now. What am I doing wrong? What is the right way to set and encode collection metadata, as well as token metadata? I would prefer to use set_collection_metadata/set_item_metadata over setting each attribute individually unless there's no other choice.

1 Answer 1

1

It is failing with IncorrectMetadata because your provided metadata is too long, i.e longer than the StringLimit constant of pallet_nfts::Config. Metadata is stored as BoundedVec, which is bounded by StringLimit length. As far as I understood, you have the pallet_nfts configured in your runtime, so you can increase the StringLimit to some value that is enough for your needs.

impl pallet_nfts::Config for Runtime {
    ...
    type StringLimit = ConstU32<512>;
    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.