SparkToken

The SparkToken class is the primary interface for interacting with tokens on the Spark network. It provides methods for creating, minting, transferring, and managing tokens, including compliance operations like freezing.

Methods

createToken(params: CreateTokenParams)

Creates a new token on Spark. For a step-by-step guide, see create your first token.

interface TokenMetadata {
  description?: string;
  image?: string;
  externalUrl?: string;
  attributes?: Record<string, string>;
}

interface CreateTokenParams {
  name: string;
  symbol: string;
  decimals: number;
  totalSupply?: string;
  metadata?: TokenMetadata;
}

async function createToken(params: CreateTokenParams): Promise<Token>;

Parameters:

  • params: (Required) An object containing:
    • name: (Required) The name of the token
    • symbol: (Required) The token symbol
    • decimals: (Required) Number of decimal places
    • totalSupply: (Optional) Initial total supply
    • metadata: (Optional) Additional token metadata

Returns:

  • Promise<Token>: The newly created token object

mintTokens(params: MintParams)

Mint new tokens to a specified address. For details, see mint your first token.

interface MintParams {
  tokenId: string;
  amount: string;
  recipient: string;
}

async function mintTokens(params: MintParams): Promise<Transaction>;

Parameters:

  • params: (Required) An object containing:
    • tokenId: (Required) The ID of the token to mint
    • amount: (Required) Amount of tokens to mint
    • recipient: (Required) Address to receive the minted tokens

Returns:

  • Promise<Transaction>: The transaction details of the mint operation

transferTokens(params: TransferParams)

Transfer tokens between addresses. Learn more in send & receive tokens.

interface TransferParams {
  tokenId: string;
  amount: string;
  recipient: string;
}

async function transferTokens(params: TransferParams): Promise<Transaction>;

Parameters:

  • params: (Required) An object containing:
    • tokenId: (Required) The ID of the token to transfer
    • amount: (Required) Amount of tokens to transfer
    • recipient: (Required) Address to receive the tokens

Returns:

  • Promise<Transaction>: The transaction details of the transfer

freezeToken(params: FreezeParams)

Freeze token transfers for compliance. See freeze & unfreeze.

interface FreezeParams {
  tokenId: string;
  freeze: boolean;
}

async function freezeToken(params: FreezeParams): Promise<Transaction>;