Get the global default SporeConfig. The default config is "predefinedSporeConfigs.Aggron4".
declare function getSporeConfig<T extends string = string>(): SporeConfig<T>;
const config = getSporeConfig();
Set the global default SporeConfig. The default config is "predefinedSporeConfigs.Aggron4".
declare function setSporeConfig<T extends string = string>(config: SporeConfig<T>): void;
setSporeConfig(predefinedSporeConfigs.Aggron4);
Clone and create a new SporeConfig.
declare function forkSporeConfig<T1 extends string, T2 extends string>(
origin: SporeConfig<T1>,
change: Partial<SporeConfig<T2>>,
): SporeConfig<T1 | T2>;
const originalConfig = predefinedSporeConfigs.Aggron4;
const forkedConfig = forkSporeConfig(originalConfig, {
maxTransactionSize: 100,
});
Get a specific SporeScript from SporeConfig by "scriptName" with optional "scriptId" or "tags". Throws an error if the script doesn't exist.
declare function getSporeScript(config: SporeConfig, scriptName: string): SporeScript;
declare function getSporeScript(config: SporeConfig, scriptName: string, tags: string[]): SporeScript;
declare function getSporeScript(config: SporeConfig, scriptName: string, scriptId: ScriptId): SporeScript;
Getting the latest version of the "Spore" script:
const sporeScript = getSporeScript(config, 'Spore');
Getting the latest "Spore" script with the "latest" tag:
const sporeScript = getSporeScript(config, 'Spore', ['latest']);
Getting the exact "Spore" script with the specified ScriptId:
const sporeScript = getSporeScript(config, 'Spore', {
codehash: '0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494',
hashType: 'data1',
});
Returns a boolean indicating whether the target ScriptId exists in the SporeConfig. If "scriptName" is passed, it also checks whether the name of the target script matches.
declare function isSporeScriptSupported(config: SporeConfig, scriptId: ScriptId, scriptName?: string): boolean;
Check if the target cell is a script supported by the SporeConfig:
const cell: Cell = { ... };
const isSupported = isSporeScriptSupported(config, cell.cellOutput.type, 'Spore');
console.log(isSupported); // true or false
Check if the target cell is a Spore:
const cell: Cell = { ... };
const isSupported = isSporeScriptSupported(config, cell.cellOutput.type, 'Spore');
console.log(isSupported); // true or false
Pack UTF-8 raw string to Uint8Array.
declare function bytifyRawString(text: string): Uint8Array;
const bytes: Uint8Array = bytifyRawString('hello world');
console.log(bytes.hexify(bytes)); // 0x07000000636f6e74656e74
Unpack Uint8Array to UTF-8 raw string.
declare function bufferToRawString(source: BytesLike, options?: TextDecodeOptions): string;
const text: string = bufferToRawString('0x07000000636f6e74656e74');
console.log(text); // content
Convert ContentType object to string.
declare function encodeContentType(encodable: EncodableContentType): string;
const contentType = encodeContentType({
type: 'image',
subtype: 'svg+xml',
parameters: {
immortal: true,
q: 0.9,
},
});
console.log(contentType); // 'image/svg+xml;immortal=true;q=0.9'
Convert string to ContentType object.
declare function decodeContentType(contentType: string): DecodedContentType;
const decoded = decodeContentType('image/svg+xml;immortal=true;q=0.9');
console.log(decoded); // { type: 'image', subtype: 'svg+xml', mediaType: 'image/svg+xml', parameters: { immortal: true, q: 0.9 } }
Check if the target ContentType's format is valid.
declare function isContentTypeValid(contentType: string): boolean;
const result1 = isContentTypeValid('image/svg+xml;immortal=true;q=0.9');
console.log(result1); // true
const result2 = isContentTypeValid('image/;test=1');
console.log(result2); // false
Wait for a transaction to be committed on-chain. Will throw an error if the transaction is not committed within approximately 2 minutes.
declare function waitForTransaction(hash: Hash, rpc: RPC): Promise<TransactionWithStatus>;
import { RPC } from '@ckb-lumos/lumos';
const rpc = new RPC(predefinedSporeConfigs.Aggron4.ckbNodeUrl);
const tx = await waitForTransaction('0x...', rpc);