CCC Docs
    Preparing search index...

    Class ErrorUdtInsufficientCoin

    Error thrown when there are insufficient UDT coins to complete a transaction. This error provides detailed information about the shortfall, including the exact amount needed, the UDT type script, and an optional custom reason.

    // This error is typically thrown automatically by UDT methods
    try {
    await udt.completeInputsByBalance(tx, signer);
    } catch (error) {
    if (error instanceof ErrorUdtInsufficientCoin) {
    console.log(`Error: ${error.message}`);
    console.log(`Shortfall: ${error.amount} UDT tokens`);
    console.log(`UDT type script: ${error.type.toHex()}`);
    }
    }

    Hierarchy

    • Error
      • ErrorUdtInsufficientCoin
    Index

    Constructors

    Properties

    Constructors

    • Creates a new ErrorUdtInsufficientCoin instance.

      Parameters

      • info: { amount: NumLike; type: ScriptLike; reason?: string }

        Configuration object for the error

        • amount: NumLike

          The amount of UDT coins that are insufficient (shortfall amount)

        • type: ScriptLike

          The type script of the UDT that has insufficient balance

        • Optionalreason?: string

          Optional custom reason message. If not provided, a default message will be generated

      Returns ErrorUdtInsufficientCoin

      // Manual creation (typically not needed as the error is thrown automatically)
      const error = new ErrorUdtInsufficientCoin({
      amount: ccc.numFrom(1000),
      type: udtScript,
      reason: "Custom insufficient balance message"
      });

      // More commonly, catch the error when it's thrown by UDT methods
      try {
      const result = await udt.completeInputsByBalance(tx, signer);
      } catch (error) {
      if (error instanceof ErrorUdtInsufficientCoin) {
      // Handle the insufficient balance error
      console.error(`Insufficient UDT: need ${error.amount} more tokens`);
      }
      }

      The error message format depends on whether a custom reason is provided:

      • With custom reason: "Insufficient coin, {custom reason}"
      • Without custom reason: "Insufficient coin, need {amount} extra coin"

    Properties

    amount: bigint

    The amount of UDT coins that are insufficient (shortfall amount). This represents how many more UDT tokens are needed to complete the operation.

    type: Script

    The type script of the UDT that has insufficient balance. This identifies which specific UDT token is lacking sufficient funds.