Implementing 'attributes' in on-chain metadata for TON NFT collection

I’m developing an NFT project on TON and need help with the metadata. I want everything to be on-chain because of the public mint feature. I’ve got most of it working, but I’m stuck on the ‘attributes’ part. Can anyone show me how to add this to the contract?

Here’s what I’ve tried so far:

cell trait_info = begin_cell()
    .store_uint(0, 8)
    .store_slice("{'type':'trait_id','data':'trait_content'}")
    .end_cell();

nft_data~dict_set_ref(256, "trait_info"H, trait_info);

It’s not quite right. How can I properly set up the ‘attributes’ field in the contract? Any tips or code examples would be really helpful. Thanks!

yo SophiaAtom88, i’ve been messin with TON NFTs too. for attributes, try this:

cell trait_cell = begin_cell()
    .store_uint(1, 8)  ;; version
    .store_dict(new_dict())  ;; empty dict for future traits
    .end_cell();

nft_data~dict_set_ref(256, 'attributes'H, trait_cell);

this sets up a flexible structure for adding traits later. whats ur nft project about? sounds dope!

I’ve worked on a similar project recently and encountered the same issue. The approach you’re taking is close, but there’s a more efficient way to handle attributes for on-chain metadata in TON NFT collections.

Instead of using a single cell for all traits, consider creating a dictionary of traits. This allows for better organization and easier access to individual attributes. Here’s a snippet that might help:

dictionary traits = new_dict();
traits~udict_set(256, 'trait_1'H, begin_cell().store_slice('trait_1_value').end_cell());
traits~udict_set(256, 'trait_2'H, begin_cell().store_slice('trait_2_value').end_cell());

cell attributes = begin_cell()
    .store_dict(traits)
    .end_cell();

nft_data~dict_set_ref(256, 'attributes'H, attributes);

This structure allows you to add multiple traits efficiently and maintains compatibility with standard NFT metadata formats. Adjust the key sizes and data types according to your specific requirements.

hey there SophiaAtom88! im curious about your NFT project on TON, sounds pretty cool :blush: i’ve been tinkering with on-chain metadata too and ran into similar hiccups. have you considered using a Cell instead of a simple string for storing the attribute data? something like this might work better:

cell trait_info = begin_cell()
    .store_uint(0, 8)
    .store_ref(begin_cell()
        .store_slice("trait_id")
        .store_slice("trait_content")
    .end_cell())
    .end_cell();

nft_data~dict_set_ref(256, "attributes"H, trait_info);

this way you can nest more complex data structures for your attributes. what kind of traits are you planning to include in your NFTs? id love to hear more about your project!