Handle Spore Data
In this recipe, we share how to handle Spore and Cluster Data using the Spore SDK.
1. Encoding and Decoding ClusterData
Ingredients:
Methods:
Encoding ClusterData with ClusterData.pack
ClusterData.packimport { ClusterData } from '@spore-sdk/core';
import { bytes } from '@ckb-lumos/codec';
const encodedClusterData = ClusterData.pack({
name: bytes.bytifyRawString('cluster name'),
description: bytes.bytifyRawString('description of the cluster'),
});
console.log(encodedClusterData); // Uint8Array [ ... ]
console.log(bytes.hexify(encodedClusterData)); // 0x3a0000000c0000001c0000000c000000636c7573746572206e616d651a0000006465736372697074696f6e206f662074686520636c7573746572Decoding ClusterData with ClusterData.unpack
ClusterData.unpack2. Encoding and Decoding SporeData
Ingredients:
Methods:
Encoding SporeData with SporeData.pack
SporeData.packDecoding SporeData with SporeData.unpack
SporeData.unpack3. Working with SporeData.contentType
Ingredients:
Methods:
Encoding SporeData.contentType with encodeContentType
encodeContentTypeDecoding SporeData.contentType with decodeContentType
decodeContentTypeUpdating the parameters of SporeData.contentType with setContentTypeParameters
setContentTypeParametersLast updated