Why Nostr? What is Njump?
2023-12-07 21:38:36

hmichellerose on Nostr: We’ve finished up the tapd demo series! But here is some bonus content on metadata. ...

We’ve finished up the tapd demo series! But here is some bonus content on metadata.

We weren’t able to fit in a metadata demo video in this round, but below are the basics of working with metadata with Taproot Assets.

First we need to note that there are many types and ways to add metadata to assets, below is the simplest.

Also, as always, have a look at the docs and the API info.
Docs: https://docs.lightning.engineering/lightning-network-tools/taproot-assets
API info: https://lightning.engineering/api-docs/api/taproot-assets/

Let’s start with the CLI. You can add metadata to an asset mint with the flag --meta_bytes
The data that you add after that flag with be encoded as hex and added to the mint. The data you add there may already be hex which means you may have to decode it twice when retrieving it.

To do that, try this command…

$ tapcli assets meta --asset_id [asset ID]

You should be able to find your metadata in the “data” value that is returned. You can then use a command similar to the below to convert that data from hex back to the original value on the command line. You’ll want to run the command once or twice depending on how you added the data.

$ echo [“data” value] | xxd -r -p && echo ''

$ echo [Output from last command] | xxd -r -p && echo ''

If you are working with tapd via the API, we’ve got some examples for you!

The below files are Python scripts for working with the REST API.

This script includes a simple metadata example: https://github.com/HannahMR/tapd-python-scripts/blob/main/mint.py

This script returns the metadata for an asset: https://github.com/HannahMR/tapd-python-scripts/blob/main/meta-data.py

This script returns the metadata and converts the result from hex to text: https://github.com/HannahMR/tapd-python-scripts/blob/main/metadata-conversion.py

I hope this helps 🧡
#keepbuilding
Author Public Key
npub1tv5j2h2742ht2a6490cdzypsxah5wlge5qyutadgphw884ynt8mqg4jlst