async function requestWithRetry(fn, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await fn();
} catch (error) {
const shouldRetry =
error.code === 'HD_WALLET_UNAVAILABLE' ||
error.code === 'RATE_LIMIT_EXCEEDED' ||
error.status >= 500;
if (!shouldRetry || attempt === maxRetries) {
throw error;
}
const delay = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
const wallet = await requestWithRetry(() =>
client.createWallet({ network: 'trc20', crypto: 'USDT' })
);