CCC Docs
    Preparing search index...

    Class ErrorCoinInsufficient

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

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

    Hierarchy

    • Error
      • ErrorCoinInsufficient
    Index
    • Creates a new ErrorCoinInsufficient instance.

      Parameters

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

        Configuration object for the error

        • amount: NumLike

          The amount of Coin that is insufficient (shortfall amount)

        • type: {} & {}

          The type script of the Coin that has insufficient amount

        • Optionalreason?: string

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

      Returns ErrorCoinInsufficient

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

      // More commonly, catch the error when it's thrown by Coin methods
      try {
      const result = await coin.completeInputsByAmount(signer, tx);
      } catch (error) {
      if (error instanceof ErrorCoinInsufficient) {
      // Handle the insufficient amount error
      console.error(`Insufficient Coin: 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"
    amount: bigint

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

    type: Script

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