TITLE: Create 4-Tier Membership DOB with Spore Protocol
DESCRIPTION: This TypeScript code snippet illustrates the complete process of creating a Spore Cluster and then minting a Spore (DOB) that represents a 4-tier membership. It defines utility functions for generating DNA and explorer URLs, and crucially, constructs the DOB/1 pattern for different membership levels, linking them to Bitcoin-inscribed SVG images. The process involves creating a cluster description, creating the cluster, and then minting the individual Spore with a generated DNA and linking it to the cluster.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/1.spore-genesis(svg_bg_btcfs_icon).md#_snippet_0
LANGUAGE: typescript
CODE:
```
import { ccc } from "@ckb-ccc/ccc";
import { client, signer } from "@ckb-ccc/playground";
function getExplorerTxUrl(txHash: string) {
const isMainnet = client.addressPrefix === 'ckb';
const baseUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://testnet.explorer.nervos.org';
return `${baseUrl}/transaction/${txHash}`
}
function generateSimpleDNA(length: number): string {
return Array.from(
{ length },
() => Math.floor(Math.random() * 16).toString(16)
).join('');
}
/**
* Generate cluster description
*/
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "Owning a Spore Genesis DOB grants exclusive access to special events, governance participation, and future airdrops within the Spore ecosystem.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "Level",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ["Gold", "Silver", "Copper", "Blue"],
},
{
traitName: "Member ID",
dobType: "String",
dnaOffset: 1,
dnaLength: 10,
patternType: "rawString",
}
];
const dob1Pattern: ccc.spore.dob.PatternElementDob1[] = [
{
imageName: "IMAGE.0",
svgFields: "attributes",
traitName: "",
patternType: "raw",
traitArgs: "xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'",
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "",
patternType: "raw",
traitArgs: ""
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Level",
patternType: "options",
traitArgs: [
["Gold", ""],
["Silver", ""],
["Copper", ""],
["Blue", ""]
]
}
];
const dob1: ccc.spore.dob.Dob1 = {
description: clusterDescription,
dob: {
ver: 1,
decoders: [
{
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
{
decoder: ccc.spore.dob.getDecoder(client, "dob1"),
pattern: dob1Pattern,
},
],
},
};
return ccc.spore.dob.encodeClusterDescriptionForDob1(dob1);
}
/**
* create cluster
*/
const { tx: clusterTx, id: clusterId } = await ccc.spore.createSporeCluster({
signer,
data: {
name: "Spore Genesis",
description: generateClusterDescriptionUnderDobProtocol(),
},
});
await clusterTx.completeFeeBy(signer, 2000n);
const clusterTxHash = await signer.sendTransaction(clusterTx);
console.log("Create cluster tx sent:", clusterTxHash, `Cluster ID: ${clusterId}`);
/**
* create spore
*/
//const clusterId = '0x77729e8e81cbeb2bf3e005e4706853405ceb45d136282894cb0b56986f4c908f';
const { tx: sporeTx, id: sporeId } = await ccc.spore.createSpore({
signer,
data: {
contentType: "dob/1",
content: ccc.bytesFrom(`{ "dna": "${generateSimpleDNA(16)}" }`, "utf8"),
clusterId: clusterId,
},
clusterMode: "clusterCell",
});
await sporeTx.completeFeeBy(signer, 2000n);
const sporeTxHash = await signer.sendTransaction(sporeTx);
console.log("Mint DOB tx sent:", sporeTxHash, `Spore ID: ${sporeId}`);
await signer.client.waitTransaction(clusterTxHash);
console.log("Create cluster tx committed:", getExplorerTxUrl(clusterTxHash), `Cluster ID: ${clusterId}`);
await signer.client.waitTransaction(sporeTxHash);
console.log("Mint DOB tx committed:", getExplorerTxUrl(sporeTxHash), `Spore ID: ${sporeId}`);
```
----------------------------------------
TITLE: Define DOB/1 Cluster Description for Tiered Membership (TypeScript)
DESCRIPTION: This function constructs the detailed DOB/1 cluster description, specifying a 4-tier membership system (Gold, Silver, Copper, Blue). It defines how DNA segments map to 'Level' and 'Member ID' traits, and how SVG image elements are dynamically generated, incorporating both IPFS and Bitcoin-inscribed (BTCFS) assets for badges.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/3.azuki-genesis(ipfs_bg_btcfs_icon).md#_snippet_0
LANGUAGE: TypeScript
CODE:
```
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "Owning a Azuki Genesis DOB grants exclusive access to special events, governance participation, and future airdrops.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "Level",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ["Gold", "Silver", "Copper", "Blue"],
},
{
traitName: "Member ID",
dobType: "String",
dnaOffset: 1,
dnaLength: 10,
patternType: "rawString",
}
];
const dob1Pattern: ccc.spore.dob.PatternElementDob1[] = [
{
imageName: "IMAGE.0",
svgFields: "attributes",
traitName: "",
patternType: "raw",
traitArgs: "xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'",
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "",
patternType: "raw",
traitArgs: ""
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Level",
patternType: "options",
traitArgs: [
["Gold", ""],
["Silver", ""],
["Copper", ""],
["Blue", ""]
]
}
];
const dob1: ccc.spore.dob.Dob1 = {
description: clusterDescription,
dob: {
ver: 1,
decoders: [
{
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
{
decoder: ccc.spore.dob.getDecoder(client, "dob1"),
pattern: dob1Pattern,
}
]
}
};
return ccc.spore.dob.encodeClusterDescriptionForDob1(dob1);
}
```
----------------------------------------
TITLE: Define DOB0 and DOB1 Patterns and Generate Cluster Description
DESCRIPTION: This function, `generateClusterDescriptionUnderDobProtocol`, defines the structure for Digital Object Blueprint (DOB) patterns, specifically DOB0 and DOB1. DOB0 defines basic traits like 'Shape' and 'BackgroundColor' using string options. DOB1 maps these traits to SVG elements and attributes, allowing for dynamic visual representation based on DNA. The function then encodes these patterns into a cluster description suitable for the Spore protocol.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/0.basic-shape.md#_snippet_1
LANGUAGE: typescript
CODE:
```
function generateClusterDescriptionUnderDobProtocol() {
/**
* Generation example for DOB0
*/
const clusterDescription = "This is a basic-shape example for dob1.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "Shape",
dobType: "String",
dnaOffset: 1,
dnaLength: 1,
patternType: "options",
traitArgs: ["circle", "square", "triangle", "star", "text"]
},
{
traitName: "BackgroundColor",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ["red", "blue", "green", "yellow", "pink"]
}
];
/**
* Generation example for DOB1
*/
const dob1Pattern: ccc.spore.dob.PatternElementDob1[] = [
{
imageName: "IMAGE.0",
svgFields: "attributes",
traitName: "",
patternType: "raw",
traitArgs: "xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'"
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "BackgroundColor",
patternType: "options",
traitArgs: [
["red", ""],
["blue", ""],
["green", ""],
["yellow", ""],
[["*"], ""]
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Shape",
patternType: "options",
traitArgs: [
["circle", ""],
["square", ""],
["triangle", ""],
["star", ""],
["text", "DOB1"],
[["*"], ""]
]
}
];
const dob1: ccc.spore.dob.Dob1 = {
description: clusterDescription,
dob: {
ver: 1,
decoders: [
{
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern
},
{
decoder: ccc.spore.dob.getDecoder(client, "dob1"),
pattern: dob1Pattern
}
]
}
};
return ccc.spore.dob.encodeClusterDescriptionForDob1(dob1);
}
```
----------------------------------------
TITLE: Create Colorful DOB with DOB/0 Protocol in TypeScript
DESCRIPTION: This TypeScript example demonstrates how to create a Data Object Bundle (DOB) with custom background and text colors using the DOB/0 protocol. It involves generating a cluster description with specific `prev.bgcolor` and `prev<%k: %v>` traits for color customization, then creating a Spore cluster and minting a DOB (spore) with a simple DNA. The `prev.bgcolor` trait sets the background color, while `prev<%k: %v>` sets the text color and outputs the property name and value. The code also includes helper functions for generating DNA and CKB explorer URLs.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob0/1.colorful-loot.md#_snippet_0
LANGUAGE: typescript
CODE:
```
import { ccc } from "@ckb-ccc/ccc";
import { client, signer } from "@ckb-ccc/playground";
function getExplorerTxUrl(txHash: string) {
const isMainnet = client.addressPrefix === 'ckb';
const baseUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://testnet.explorer.nervos.org';
return `${baseUrl}/transaction/${txHash}`
}
function generateSimpleDNA(length: number): string {
return Array.from(
{ length },
() => Math.floor(Math.random() * 16).toString(16)
).join('');
}
/**
* Generate cluster description
*/
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "A colorful loot cluster";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "prev.bgcolor",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ['#DBAB00', '#FFBDFC', '#09D3FF', '#AFE7F9', '#66C084'],
},
{
traitName: "prev<%k: %v>",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ['#FFFFFF', '#000000', '#FFBDFC', '#000000', '#FFFFFF']
},
{
traitName: "Type",
dobType: "Number",
dnaOffset: 1,
dnaLength: 1,
patternType: "range",
traitArgs: [10, 50],
},
{
traitName: "Timestamp",
dobType: "Number",
dnaOffset: 2,
dnaLength: 4,
patternType: "rawNumber",
},
];
const dob0: ccc.spore.dob.Dob0 = {
description: clusterDescription,
dob: {
ver: 0,
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
};
return ccc.spore.dob.encodeClusterDescriptionForDob0(dob0);
}
/**
* create cluster
*/
const { tx: clusterTx, id: clusterId } = await ccc.spore.createSporeCluster({
signer,
data: {
name: "Colorful loot",
description: generateClusterDescriptionUnderDobDobProtocol(),
},
});
await clusterTx.completeFeeBy(signer, 2000n);
const clusterTxHash = await signer.sendTransaction(clusterTx);
console.log("Create cluster tx sent:", clusterTxHash, `Cluster ID: ${clusterId}`);
await signer.client.waitTransaction(clusterTxHash);
console.log("Create cluster tx committed:", getExplorerTxUrl(clusterTxHash), `Cluster ID: ${clusterId}`);
/**
* create spore
*/
const { tx: sporeTx, id: sporeId } = await ccc.spore.createSpore({
signer,
data: {
contentType: "dob/0",
content: ccc.bytesFrom(`{ "dna": "${generateSimpleDNA(16)}" }`, "utf8"),
clusterId: clusterId,
},
clusterMode: "clusterCell",
});
await sporeTx.completeFeeBy(signer, 2000n);
const sporeTxHash = await signer.sendTransaction(sporeTx);
console.log("Mint DOB tx sent:", sporeTxHash, `Spore ID: ${sporeId}`);
await signer.client.waitTransaction(sporeTxHash);
console.log("Mint DOB tx committed:", getExplorerTxUrl(sporeTxHash), `Spore ID: ${sporeId}`);
```
----------------------------------------
TITLE: Create Spore Cluster and Mint Spore with DOB Content
DESCRIPTION: This snippet demonstrates the end-to-end process of creating a Spore cluster and then minting a Spore within that cluster. It first creates a cluster with a name and a dynamically generated DOB description. Subsequently, it mints a new Spore, assigning it a `dob/0` content type and a randomly generated DNA, linking it to the newly created cluster. Finally, it sends and waits for both transactions to be committed on the CKB blockchain, logging their explorer URLs and IDs.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/0.basic-shape.md#_snippet_2
LANGUAGE: typescript
CODE:
```
/**
* create cluster
*/
const { tx: clusterTx, id: clusterId } = await ccc.spore.createSporeCluster({
signer,
data: {
name: "dob1-basic-shape",
description: generateClusterDescriptionUnderDobProtocol()
}
});
await clusterTx.completeFeeBy(signer, 2000n);
const clusterTxHash = await signer.sendTransaction(clusterTx);
console.log("Create cluster tx sent:", clusterTxHash, `Cluster ID: ${clusterId}`);
/**
* create spore
*/
//const clusterId = '0xc2e4164c6b390b0ca31138d1715201c24dc9aafae1a75b1047763cd06602de4e';
const { tx: sporeTx, id: sporeId } = await ccc.spore.createSpore({
signer,
data: {
contentType: "dob/0",
content: ccc.bytesFrom(`{ \"dna\": \"${generateSimpleDNA(16)}\" }`, "utf8"),
clusterId: clusterId
},
clusterMode: "clusterCell"
});
await sporeTx.completeFeeBy(signer, 2000n);
const sporeTxHash = await signer.sendTransaction(sporeTx);
console.log("Mint DOB tx sent:", sporeTxHash, `Spore ID: ${sporeId}`);
await signer.client.waitTransaction(clusterTxHash);
console.log("Create cluster tx committed:", getExplorerTxUrl(clusterTxHash), `Cluster ID: ${clusterId}`);
await signer.client.waitTransaction(sporeTxHash);
console.log("Mint DOB tx committed:", getExplorerTxUrl(sporeTxHash), `Spore ID: ${sporeId}`);
```
----------------------------------------
TITLE: TypeScript: Generate DOB/1 Cluster Description for Membership System
DESCRIPTION: Defines the structure and patterns for a DOB/1 cluster description, specifically for a 4-tier membership system. It includes `dob0Pattern` for 'Level' and 'Member ID' traits, and `dob1Pattern` for image attributes and elements, linking membership tiers to specific badge images inscribed on Bitcoin.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/2.nervape-genesis(btcfs_bg_btcfs_icon).md#_snippet_1
LANGUAGE: typescript
CODE:
```
/**
* Generate cluster description
*/
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "Owning a Nervape Genesis DOB grants exclusive access to special events, governance participation, and future airdrops.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "Level",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ["Gold", "Silver", "Copper", "Blue"],
},
{
traitName: "Member ID",
dobType: "String",
dnaOffset: 1,
dnaLength: 10,
patternType: "rawString",
}
];
const dob1Pattern: ccc.spore.dob.PatternElementDob1[] = [
{
imageName: "IMAGE.0",
svgFields: "attributes",
traitName: "",
patternType: "raw",
traitArgs: "xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 500'",
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "",
patternType: "raw",
traitArgs: ""
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Level",
patternType: "options",
traitArgs: [
["Gold", ""],
["Silver", ""],
["Copper", ""],
["Blue", ""]
]
}
];
const dob1: ccc.spore.dob.Dob1 = {
description: clusterDescription,
dob: {
ver: 1,
decoders: [
{
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
{
decoder: ccc.spore.dob.getDecoder(client, "dob1"),
pattern: dob1Pattern,
},
],
},
};
return ccc.spore.dob.encodeClusterDescriptionForDob1(dob1);
}
```
----------------------------------------
TITLE: Create DOB with Regular Image URLs using DOB/0 Protocol (TypeScript)
DESCRIPTION: This TypeScript example demonstrates the creation of a Digital Object (DOB) using the DOB/0 protocol. It includes functions to generate a simple DNA string, construct a cluster description with specific traits (`prev.type`, `prev.bg`), and then create both a Spore cluster and a Spore (DOB) on the CKB blockchain, using regular image URLs for rendering.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob0/5.regular-link-svg.md#_snippet_0
LANGUAGE: typescript
CODE:
```
import { ccc } from "@ckb-ccc/ccc";
import { client, signer } from "@ckb-ccc/playground";
function getExplorerTxUrl(txHash: string) {
const isMainnet = client.addressPrefix === 'ckb';
const baseUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://testnet.explorer.nervos.org';
return `${baseUrl}/transaction/${txHash}`
}
function generateSimpleDNA(length: number): string {
return Array.from(
{ length },
() => Math.floor(Math.random() * 16).toString(16)
).join('');
}
/**
* Generate cluster description
*/
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "A cluster with regular link svg as the primary rendering objects.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "prev.type",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ['image'],
},
{
traitName: "prev.bg",
dobType: "String",
dnaOffset: 1,
dnaLength: 1,
patternType: "options",
traitArgs:[
"https://www.nervos.org/favicon.svg",
],
},
{
traitName: "Type",
dobType: "Number",
dnaOffset: 3,
dnaLength: 1,
patternType: "range",
traitArgs: [10, 50],
},
{
traitName: "Timestamp",
dobType: "Number",
dnaOffset: 4,
dnaLength: 4,
patternType: "rawNumber",
},
];
const dob0: ccc.spore.dob.Dob0 = {
description: clusterDescription,
dob: {
ver: 0,
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
};
return ccc.spore.dob.encodeClusterDescriptionForDob0(dob0);
}
/**
* create cluster
*/
const { tx: clusterTx, id: clusterId } = await ccc.spore.createSporeCluster({
signer,
data: {
name: "Regular link SVG",
description: generateClusterDescriptionUnderDobProtocol(),
},
});
await clusterTx.completeFeeBy(signer, 2000n);
const clusterTxHash = await signer.sendTransaction(clusterTx);
console.log("Create cluster tx sent:", clusterTxHash, `Cluster ID: ${clusterId}`);
await signer.client.waitTransaction(clusterTxHash);
console.log("Create cluster tx committed:", getExplorerTxUrl(clusterTxHash), `Cluster ID: ${clusterId}`);
/**
* create spore
*/
//const clusterId = '0x3ae41180f64a22ad6c73058d27f956f8195c17bab3bc03222b5e5683771407c4';
const { tx: sporeTx, id: sporeId } = await ccc.spore.createSpore({
signer,
data: {
contentType: "dob/0",
content: ccc.bytesFrom(`{ "dna": "${generateSimpleDNA(16)}" }`, "utf8"),
clusterId: clusterId,
},
clusterMode: "clusterCell",
});
await sporeTx.completeFeeBy(signer, 2000n);
const sporeTxHash = await signer.sendTransaction(sporeTx);
console.log("Mint DOB tx sent:", sporeTxHash, `Spore ID: ${sporeId}`);
await signer.client.waitTransaction(sporeTxHash);
console.log("Mint DOB tx committed:", getExplorerTxUrl(sporeTxHash), `Spore ID: ${sporeId}`);
```
----------------------------------------
TITLE: Construct Spore Protocol DOB1 Object with Decoders
DESCRIPTION: This TypeScript snippet demonstrates how to construct a `Dob1` object for the Spore Protocol. It includes a `description` and defines an array of `decoders`, each associated with a specific `pattern`. The `ccc.spore.dob.getDecoder` function is used to retrieve decoders from a client, and the `ccc.spore.dob.encodeClusterDescriptionForDob1` function is called to process the constructed `Dob1` object, preparing it for use within the protocol.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/4.nervape-compose(btcfs).md#_snippet_2
LANGUAGE: TypeScript
CODE:
```
const dob1: ccc.spore.dob.Dob1 = {
description: clusterDescription,
dob: {
ver: 1,
decoders: [
{
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
{
decoder: ccc.spore.dob.getDecoder(client, "dob1"),
pattern: dob1Pattern,
}
]
}
};
return ccc.spore.dob.encodeClusterDescriptionForDob1(dob1);
```
----------------------------------------
TITLE: Create DOB/0 Cluster and Spore with BTCFS i0 SVG
DESCRIPTION: This TypeScript code demonstrates the end-to-end process of creating a Spore cluster and minting a DOB (Digital Object Blueprint) based on the DOB/0 protocol. It defines a DOB/0 pattern using `btcfs://` SVG image links for rendering, generates a simple DNA, and then executes the transactions to create the cluster and mint the spore on the CKB blockchain.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob0/6.btcfs-i0-svg.md#_snippet_0
LANGUAGE: TypeScript
CODE:
```
import { ccc } from "@ckb-ccc/ccc";
import { client, signer } from "@ckb-ccc/playground";
function getExplorerTxUrl(txHash: string) {
const isMainnet = client.addressPrefix === 'ckb';
const baseUrl = isMainnet ? 'https://explorer.nervos.org' : 'https://testnet.explorer.nervos.org';
return `${baseUrl}/transaction/${txHash}`
}
function generateSimpleDNA(length: number): string {
return Array.from(
{ length },
() => Math.floor(Math.random() * 16).toString(16)
).join('');
}
/**
* Generate cluster description
*/
function generateClusterDescriptionUnderDobProtocol() {
const clusterDescription = "A cluster with btcfs i0 svg as the primary rendering objects.";
const dob0Pattern: ccc.spore.dob.PatternElementDob0[] = [
{
traitName: "prev.type",
dobType: "String",
dnaOffset: 0,
dnaLength: 1,
patternType: "options",
traitArgs: ['image'],
},
{
traitName: "prev.bg",
dobType: "String",
dnaOffset: 1,
dnaLength: 1,
patternType: "options",
traitArgs:[
"btcfs://8ca2da44996f5a06ad44b5bb87fd9acb71390b6c0cb1910c10b0deb8daad7f82i0",
],
},
{
traitName: "prev.bgcolor",
dobType: "String",
dnaOffset: 2,
dnaLength: 1,
patternType: "options",
traitArgs:[
"#FFC103",
],
},
{
traitName: "Type",
dobType: "Number",
dnaOffset: 3,
dnaLength: 1,
patternType: "range",
traitArgs: [10, 50],
},
{
traitName: "Timestamp",
dobType: "Number",
dnaOffset: 4,
dnaLength: 4,
patternType: "rawNumber",
},
];
const dob0: ccc.spore.dob.Dob0 = {
description: clusterDescription,
dob: {
ver: 0,
decoder: ccc.spore.dob.getDecoder(client, "dob0"),
pattern: dob0Pattern,
},
};
return ccc.spore.dob.encodeClusterDescriptionForDob0(dob0);
}
/**
* create cluster
*/
const { tx: clusterTx, id: clusterId } = await ccc.spore.createSporeCluster({
signer,
data: {
name: "BTCFS i0 SVG",
description: generateClusterDescriptionUnderDobProtocol(),
},
});
await clusterTx.completeFeeBy(signer, 2000n);
const clusterTxHash = await signer.sendTransaction(clusterTx);
console.log("Create cluster tx sent:", clusterTxHash, `Cluster ID: ${clusterId}`);
await signer.client.waitTransaction(clusterTxHash);
console.log("Create cluster tx committed:", getExplorerTxUrl(clusterTxHash), `Cluster ID: ${clusterId}`);
/**
* create spore
*/
//const clusterId = '0xd74f0b5c866f0f04958426213781ddb80e9cd730c78d24f7c149aad18d3bc8bd';
const { tx: sporeTx, id: sporeId } = await ccc.spore.createSpore({
signer,
data: {
contentType: "dob/0",
content: ccc.bytesFrom(`{ "dna": "${generateSimpleDNA(16)}" }`, "utf8"),
clusterId: clusterId,
},
clusterMode: "clusterCell",
});
await sporeTx.completeFeeBy(signer, 2000n);
const sporeTxHash = await signer.sendTransaction(sporeTx);
console.log("Mint DOB tx sent:", sporeTxHash, `Spore ID: ${sporeId}`);
await signer.client.waitTransaction(sporeTxHash);
console.log("Mint DOB tx committed:", getExplorerTxUrl(sporeTxHash), `Spore ID: ${sporeId}`);
```
----------------------------------------
TITLE: Define Spore Protocol DOB Image Traits and Assets
DESCRIPTION: This snippet defines various image-based traits for a Digital Object (DOB) within the Spore Protocol. Each trait includes an 'imageName', 'svgFields', 'traitName', 'patternType', and a 'traitArgs' array. Each 'traitArgs' entry is a pair of a trait option name and an SVG image reference pointing to a 'btcfs' (Bitcoin File System) URI. This structure is used to specify different visual components like masks, earrings, accessories, and clothing for a digital asset.
SOURCE: https://github.com/sporeprotocol/dob-cookbook/blob/main/examples/dob1/4.nervape-compose(btcfs).md#_snippet_1
LANGUAGE: TypeScript
CODE:
```
["Zombie Mask", ""],
["Opera Mask Wukong", ""],
["Bonelist Mask", ""],
["Goofy Eyes Soup", ""],
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Ears",
patternType: "options",
traitArgs: [
["Daisy Earrings Yellow", ""],
["Bone Earrings Blue Purple", ""],
["Apple Earrings Red", ""],
["Feather Earrings", ""],
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Accessory",
patternType: "options",
traitArgs: [
["Nervape Figure Green", ""],
["Assorted Rings Gold", ""],
["Bitcoin Chain", ""],
["Nervos Chain", ""],
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Upper body",
patternType: "options",
traitArgs: [
["Tee POW", ""],
["Faux Fur Coat Pink", ""],
["Short-Sleeve Button-up Nervape Blue", ""],
["Tee Bitcoin Pattern", ""],
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Lower body",
patternType: "options",
traitArgs: [
["Cargo Shorts", ""],
["Knife Pleated Skirt Denim Blue", ""],
["Swimming Trunks POW BOOM", ""],
["Fishnet Stocking", ""],
]
},
{
imageName: "IMAGE.0",
svgFields: "elements",
traitName: "Handheld",
patternType: "options",
traitArgs: [
["Skateboard Red", ""],
["Ruyi Jingu Bang", ""],
["Coin BTC", ""],
["Coin CKB", ""],
]
}
];
```