Skip to main content

Create Spore

In the recipe, you will learn how to create a spore on-chain using the spore-sdk.

Create a Spore

You can create a spore with 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,
},
toLock: OWNER_LOCK,
fromInfos: [SPONSOR_ADDRESS],
});
  • data - The spore's data, including file data relevant properties.
  • toLock - The lock script specifies the spore's ownership.
  • fromInfos - The transaction's sponsors, specifies where to collect capacity from.

Extras

Code example

A spore creation transaction involves 3 steps: construct, sign, and send. This recipe focuses on the transaction construction. For a valid on-chain transaction, you'll need to sign the transaction and send it to the chain.

Here's a code example for how to create a spore with CKB default lock:

createSpore.ts
Create a Spore on-chain with CKB default lock
https://github.com/sporeprotocol/spore-sdk/blob/beta/examples/secp256k1/apis/createSpore.ts

Modify the Zero-fee Transfer feature

The Zero-fee Transfer feature enables recipients to transact spores without additional costs by reserving a tiny amount of CKBytes as fee for future transactions. When creating a spore, the default is to allocate 1 CKB (100,000,000 shannons) as capacity margin to cover about 100,000 future transaction. To adjust the margin amount for the new spore, you can set the capacityMargin prop, for example, to 2 CKB like this:

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

let { txSkeleton } = await createSpore({
...
capacityMargin: BI.from(2_0000_0000), // 2 CKB
});

Configure transaction size limits

By default, spore-sdk limits the size of spore creation transactions to be ≤500KB (500 * 1024 bytes), any spore creation transactions exceeding the size limit will not succeed.

You have the option to lower the limit when calling the createSpore API:

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

let { txSkeleton } = await createSpore({
...
maxTransactionSize: 400 * 1024,
});

Or pass a false to disable the limit:

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

let { txSkeleton } = await createSpore({
...
maxTransactionSize: false,
});