Open Cap Table Protocol Canton SDK - v0.2.224
    Preparing search index...

    Function mintWithRateLimit

    • Waits until minting is allowed, then executes the provided mint function.

      This is a "fire and forget" style wrapper that handles rate limiting automatically. It waits for the rate limit to allow minting, then executes your mint function.

      Type Parameters

      • T

      Parameters

      • payload: CouponMinterPayload

        The CouponMinter contract payload with rate limit state

      • mintFn: () => Promise<T>

        The async function to execute once minting is allowed

      • Optionaloptions: MintWithRateLimitOptions

        Optional configuration for the wait and mint operation

      Returns Promise<MintWithRateLimitResult<T>>

      Promise resolving to the mint result along with rate limit metadata

        // Simple usage with async mint function
      const { result, wasRateLimited, waitedMs } = await mintWithRateLimit(
      couponMinterPayload,
      async () => {
      return await ledgerClient.exerciseChoice(
      couponMinterCid,
      'MintCoupons',
      mintParams
      );
      }
      );
      console.log(`Minting complete. Rate limited: ${wasRateLimited}, waited: ${waitedMs}ms`);
        // With callbacks for progress tracking
      const { result } = await mintWithRateLimit(
      couponMinterPayload,
      async () => mintCoupons(params),
      {
      onWaitStart: (ms) => console.log(`Rate limited, waiting ${ms}ms...`),
      onBeforeMint: () => console.log('Submitting mint transaction...'),
      maxWaitMs: 60000,
      }
      );

      WaitAbortedError if the operation is aborted via the signal

      WaitTimeoutError if the maximum wait time is exceeded

      Any error thrown by the mintFn