The CouponMinter contract payload with rate limit state
The async function to execute once minting is allowed
Optionaloptions: MintWithRateLimitOptionsOptional configuration for the wait and mint operation
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,
}
);
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.