Features

Deserialization

Digital assets on Core are composed of exactly one onchain account that contains both the base asset data and the plugin.

That means that if we want to read that data we need to learn how to deserialize it.

In Javascript we can deserialize both the base asset data and the plugin using a single function. In Rust we should deserialize the base asset and only the required plugins separately to avoid unnecessary compute usage and to prevent overflowing the stack.

Deserializing Assets

Deserializing the Asset account will return information about:

  • Owner: The owner of the asset
  • Update Authority: The authority over the asset, or the collection Address if it's part of one
  • Name: The Asset Name
  • Uri: The uri to the asset off-chain metadata. -->

Deserialize an Asset

const accountData = await umi.rpc.getAccount(
  publicKey('11111111111111111111111111111111')
)

if (!accountData.exists) throw 'Account does not exist'

const assetV1 = deserializeAssetV1(accountData)

console.log({ assetData })

Deserializing Collections

Deserializing the Collection account will return information about:

  • Update Authority: The authority over the collection and all the asset inside of it
  • Name: The collection name.
  • Uri: The uri to the collections off-chain metadata.
  • Num Minted: The number of assets minted in the collection.
  • Current size: The number of assets currently in the collection.

Deserialize a Collection

const accountData = await umi.rpc.getAccount(
  publicKey('11111111111111111111111111111111')
)

if (!accountData.exists) throw 'Account does not exist'

const collectionV1 = deserializeCollectionV1(accountData)

console.log({ assetData })

Deserializing Plugins

As said before,

  • Using Javascript we can deserialize the whole asset into a single variable, in this section we're going to see how we can access the specific data associated with the plugins.
  • Using Rust we need to deserialize specific plugin data to avoid stack violation because of the size of the account.

Deserialize Plugins

const assetV1 = await fetchAsset(
  umi,
  publicKey('11111111111111111111111111111111')
)

// Example of saving just the deserialized data of the Attributes Plugin
let attributes_plugin = assetV1.attributes

// Example of saving just the deserialized data of the Royalties Plugin
let royalties_plugin = assetV1.royalties
Previous
Helpers