import {
sendUTXOTransaction,
waitForTransaction,
withRetry,
TimeoutError,
TransactionNotFoundError,
getBalance
} from '@bigmi/core'
// Using Bigmi's built-in withRetry utility
// Simple retry with fixed delay
async function getBalanceWithRetry(client, address) {
return withRetry(
() => getBalance(client, { address }),
{
delay: 2000, // 2 seconds between retries
retryCount: 3, // Try 3 times total
}
)
}
async function sendTransactionWithRetry(client, txHex) {
// Retry transaction broadcasting with exponential backoff
const txId = await withRetry(
() => sendUTXOTransaction(client, { hex: txHex }),
{
delay: ({ count }) => Math.pow(2, count) * 1000, // 1s, 2s, 4s...
retryCount: 3,
shouldRetry: ({ error }) =>
error instanceof TimeoutError ||
error instanceof TransactionNotFoundError
}
)
// Wait for confirmation with retry logic
const receipt = await withRetry(
() => waitForTransaction(client, {
txId,
txHex,
timeout: 30_000 // 30 seconds per attempt
}),
{
delay: 5000, // 5 second delay between retries
retryCount: 5,
shouldRetry: ({ error }) => error instanceof TimeoutError
}
)
return receipt
}