taproot-assets icon indicating copy to clipboard operation
taproot-assets copied to clipboard

How to create pictures / nfts, "the correct way"

Open weltitob opened this issue 1 year ago • 9 comments

Is it intended of the usage of the network that, IPFS filestorage is done when NFTS are created or is the network well capable and does also inted to store images directly in the metadata.

If I store a picture directly, should I store its bytes or whats the best storage option

Is there a dedicated command to store pictures specifically?

weltitob avatar Feb 07 '24 10:02 weltitob

Great question!

I think the best way to create a collection is using the group key system. What this does is assign a unique public key that's capable of minting future items into the collection, and can also be used to authenticate the creator of the collection as well. Each item in the collection will have a unique asset_id, but they'll have the same group_key. The group_key is then used as a main sub-tree in the Universe tree. Today the group key is just a single sig to unlock, but in the near future, it can be multi-sig or w/e other script.

Here's a doc example that shows creating a new asset with a group key, then later on adding additional asset to be minted. You can also make the first grouped asset, then all the others in the same batch (single transaction on chain to create N) collectibles.

As far as storage, you can either put the data directly into the asset_meta (meta_bytes, or `meta_file) or put some more structured or indirect information instead. If you put the data in the asset meta, then each time users fetch the genesis asset to boostrap (like fetching an initial commit in a git repo), they'll also obtain that asset meta. We have built in calls to allow users to fetch the data: https://lightning.engineering/api-docs/api/taproot-assets/taproot-assets/fetch-asset-meta.

When you specify an asset meta, that impacts the asset_id, because the hash of the asset meta is included into the asset ID. The group key however, will stay the same. Here's some additional docs re how to create all your assets in a single batch, specify meta (you'd likely want to use the file option for an image, then finalize: https://docs.lightning.engineering/lightning-network-tools/taproot-assets/collectibles.

We're also looking to standardize the meta field a bit: https://github.com/lightninglabs/taproot-assets/issues/783. That'll allow you to specify an IPFS link or w/e instead of attaching the image directly. You can also do a hybrid of both, to do things like attach "attributes" to each asset via the meta.

Roasbeef avatar Feb 07 '24 19:02 Roasbeef

For embedding the image, the --meta_file_path will be useful.

For recovering the image:

# fetch raw metadata from tapd
$META="$TAPD assets meta --asset_id $ASSET_ID"

# extract just the metadata field
$META_HEX="$(echo $META | jq '.data' | tr -d '"')"

# convert from hex to binary and write to file
echo "$META_HEX" | xxd -r -p > "$ASSET_ID"_meta.meta

Or something similar.

jharveyb avatar Feb 07 '24 20:02 jharveyb

what about gifs can I also simply use the --meta_file_path I assume I would be able to recover it similarlly is that right? And another question would be about attributes normally you would save them in the metadata field aswell and if I use the file path to upload something I'm not able to add any other data to the metafield like that, right?

Thats how you would normally do it on other chains, I think would change the image field here for a gif field and add the binary of the gif

{ "name": "Mein tolles NFT", "description": "Ein wirklich cooles animiertes GIF als NFT", "image": "https://meinedomain.com/pfad/zum/gif/mein-tolles-nft.gif", "attributes": [ { "trait_type": "Seltenheit", "value": "Selten" }, { "trait_type": "Stimmung", "value": "Fröhlich" } ] }

I know it's a new technology and there might be no standards yet but if there are please let me know espacially for additinoal data I'd like to store for a png or a gif

weltitob avatar Feb 08 '24 22:02 weltitob

If you want to also embed other fields alongside raw data that could be a GIF or image, I'd recommend using a JSON value with a tag like data:image/jpg;base64, so that others would know how to decode it.

We are working on supporting JSON as an official metadata type, but for right now you could build a JSON object and then convert it to binary and supply that to tapd.

There is this related proposal by another community member that you may find useful:

https://github.com/snow884/taproot-assets-metadata-format

jharveyb avatar Feb 08 '24 23:02 jharveyb

If you want to also embed other fields alongside raw data that could be a GIF or image, I'd recommend using a JSON value with a tag like data:image/jpg;base64, so that others would know how to decode it.

We are working on supporting JSON as an official metadata type, but for right now you could build a JSON object and then convert it to binary and supply that to tapd.

There is this related proposal by another community member that you may find useful:

https://github.com/snow884/taproot-assets-metadata-format

I see. Depending on the link you provided I would save a gif in the metadatafield like that:

{ "acronym": "MyTestGIF", "description": "This is my test GIF", "image_data": "data:image/gif;base64,....." }

This would also follow web standard of img. Can you please confirm that's how you recommend me to do it?

weltitob avatar Feb 09 '24 09:02 weltitob

If you want to also embed other fields alongside raw data that could be a GIF or image, I'd recommend using a JSON value with a tag like data:image/jpg;base64, so that others would know how to decode it.

We are working on supporting JSON as an official metadata type, but for right now you could build a JSON object and then convert it to binary and supply that to tapd.

There is this related proposal by another community member that you may find useful:

https://github.com/snow884/taproot-assets-metadata-format

Oh and I'd probably also replace acronym for name because thats also the standard here and I dont see why one shouldnt/ wouldnt want to follow that: https://docs.opensea.io/docs/metadata-standards

weltitob avatar Feb 09 '24 09:02 weltitob

@weltitob I made this PR to make the JSON meta standard in the API: https://github.com/lightninglabs/taproot-assets/pull/794

Roasbeef avatar Feb 15 '24 00:02 Roasbeef

@weltitob I made this PR to make the JSON meta standard in the API: #794

@Roasbeef Hi can you give me an example how I would now save a png and also gif correctly based on the standard or can you reference me some documentation?

weltitob avatar Apr 19 '24 13:04 weltitob

Hi can you give me an example how I would now save a png and also gif correctly based on the standard or can you reference me some documentation?

The link the snow884's repo above seems like a decent option, along with this:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs

I would recommend you discuss the standard with other developers using Taproot Assets in the Slack.

jharveyb avatar Apr 23 '24 16:04 jharveyb