Creates a new token on Spark using Spark Native Tokens for the IssuerSparkWallet.
Method Signature
// Returns transaction hash only
async createToken({
tokenName,
tokenTicker,
decimals,
maxSupply,
isFreezable,
extraMetadata,
returnIdentifierForCreate,
}: {
tokenName: string;
tokenTicker: string;
decimals: number;
maxSupply?: bigint; // defaults to 0n (unlimited)
isFreezable: boolean;
extraMetadata?: Uint8Array;
returnIdentifierForCreate?: false;
}): Promise<string>
// Returns both transaction hash and token identifier
async createToken({
tokenName,
tokenTicker,
decimals,
maxSupply,
isFreezable,
extraMetadata,
returnIdentifierForCreate,
}: {
tokenName: string;
tokenTicker: string;
decimals: number;
maxSupply?: bigint; // defaults to 0n (unlimited)
isFreezable: boolean;
extraMetadata?: Uint8Array;
returnIdentifierForCreate: true;
}): Promise<TokenCreationDetails>
Parameters
Name of the token (eg: SparkCoin)
Token ticker (eg: SPARKC)
The precision the token supports (eg: 8 for BTC)
The maximum supply for this token (defaults to 0n for unlimited supply)
Whether or not the Issuer can freeze this token
Optional extra metadata bytes to associate with the token (e.g., image data, JSON metadata)
returnIdentifierForCreate
When true, returns both the transaction hash and token identifier as TokenCreationDetails. When false or omitted, returns only the transaction hash as a string (default: false)
Returns
When returnIdentifierForCreate is false or omitted:
When returnIdentifierForCreate is true:
result
TokenCreationDetails
required
Object containing:
tokenIdentifier: Bech32m token identifier (e.g., btkn1...)
transactionHash: Spark Transaction ID
Example
// Basic usage - returns only transaction hash
const txId = await issuerWallet.createToken({
tokenName: "SparkCoin",
tokenTicker: "SPARKC",
decimals: 8,
maxSupply: 1000000n,
isFreezable: true,
// Optional: add extra metadata
extraMetadata: new TextEncoder().encode(JSON.stringify({ icon: "..." }))
});
console.log("Token created:", txId);
// Get both transaction hash and token identifier
const result = await issuerWallet.createToken({
tokenName: "SparkCoin",
tokenTicker: "SPARKC",
decimals: 8,
maxSupply: 1000000n,
isFreezable: true,
returnIdentifierForCreate: true
});
console.log("Token created:", result.transactionHash);
console.log("Token identifier:", result.tokenIdentifier);