Skip to main content

Create Clustered Spore

In this recipe, you’ll learn how to tag a Cluster when creating a Spore. If you are looking to create standalone spores (spores without cluster) refer to: Create a Spore.

caution
  • You can only utilize a Cluster as a tag if it can be unlocked by you to use.
  • You cannot tag a Spore after its creation; you'll need to melt and then tag it during the creation process.
  • Each Spore can be associated with only one Cluster.

Your target cluster can be either a public cluster or a private cluster, depending on its lock script.

spore-in-cluster-flowchart.png

Create Clustered Spore With ClusterID

You can tag a spore with a cluster by specifying the data.clusterId when calling the createSpore API from spore-sdk:

import { createSpore } from '@spore-sdk/core';

let { txSkeleton } = await createSpore({
data: {
contentType: CONTENT_MIME_TYPE,
content: CONTENT_AS_BYTES,
clusterId: CLUSTER_ID,
},
toLock: OWNER_LOCK,
fromInfos: [SPONSOR_ADDRESS],
});
  • data.clusterId - The ID of the cluster to be assigned to the spore. The cluster's ID is equivalent to the type script args of the cluster.

Code example

createSporeWithCluster.ts
Create a Clustered Spore on-chain
https://github.com/sporeprotocol/spore-sdk/blob/beta/examples/secp256k1/apis/createSporeWithCluster.ts
createSporeWithAcpCluster.ts
Create a Clustered Spore with ACP Public Cluster
https://github.com/sporeprotocol/spore-sdk/blob/beta/examples/acp/apis/createSporeWithAcpCluster.ts
createSporeWithOmnilockCluster.ts
Create a Clustered Spore with Omnilock Public Cluster
https://github.com/sporeprotocol/spore-sdk/blob/beta/examples/omnilock/acp/createSporeWithAcpCluster.ts

Create Clustered Spore With Cluster Agent

You can tag a spore with a cluster by referencing ClusterAgent when calling the createSpore API from spore-sdk:

import { createSpore } from '@spore-sdk/core';

let { txSkeleton, outputIndex } = await createSpore({
data: {
contentType: CONTENT_MIME_TYPE,
content: CONTENT_AS_BYTES,
clusterId: CLUSTER_ID,
},
clusterAgentOutPoint,
toLock: OWNER_LOCK,
fromInfos: [SPONSOR_ADDRESS],
});
  • data.clusterId - The ID of the cluster to be assigned to the spore. The cluster's ID is equivalent to the type script args of the cluster.
  • clusterAgentOutPoint - The ClusterAgent you want to reference in the transaction

Code example

createSporeWithClusterAgent.ts
Create a Clustered Spore with Cluster Agent on-chain
https://github.com/sporeprotocol/spore-sdk/blob/beta/examples/secp256k1/apis/createSporeWithClusterAgent.ts