The CouponMinter contract payload with rate limit state
Optionaloptions: WaitUntilCanMintOptionsOptional configuration for the wait operation
Promise that resolves when minting is allowed
// Wait until we can mint, then proceed
await waitUntilCanMint(couponMinterPayload);
await mintCoupons(...);
// Wait with a timeout and abort support
const controller = new AbortController();
setTimeout(() => controller.abort(), 10000); // 10 second timeout
try {
await waitUntilCanMint(couponMinterPayload, {
maxWaitMs: 30000,
signal: controller.signal,
onWaitStart: (ms) => console.log(`Waiting ${ms}ms for rate limit...`),
});
await mintCoupons(...);
} catch (error) {
if (error instanceof WaitAbortedError) {
console.log('Wait was cancelled');
}
}
Waits until coupon minting is allowed based on the current rate limit state.
This function will sleep until the rate limit allows minting, checking periodically until either minting is allowed or the maximum wait time is exceeded.