Skip to content

Commit 376ebd6

Browse files
committed
fix: throttle RPC calls to avoid rate limits
- Reduce MAX_TXS from 50 to 20 - Add 500ms delay between RPC batch requests - Applies to SOL, USDC, and SPL token history fetchers - Bump to v0.4.15
1 parent f8b5062 commit 376ebd6

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coinpayportal",
3-
"version": "0.4.14",
3+
"version": "0.4.15",
44
"private": true,
55
"type": "module",
66
"bin": {

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@profullstack/coinpay",
3-
"version": "0.4.14",
3+
"version": "0.4.15",
44
"description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) with wallet and swap support",
55
"type": "module",
66
"main": "./src/index.js",

src/lib/web-wallet/tx-indexer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const TRANSFER_TOPIC =
8585
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
8686

8787
/** Max transactions per scan */
88-
const MAX_TXS = 50;
88+
const MAX_TXS = 20;
89+
const RPC_BATCH_DELAY_MS = 500; // Delay between RPC batches to avoid rate limits
90+
const rpcDelay = () => new Promise((r) => setTimeout(r, RPC_BATCH_DELAY_MS));
8991

9092
/** Truncate address for logging */
9193
function truncAddr(addr: string): string {
@@ -849,6 +851,7 @@ async function fetchSOLHistory(
849851
});
850852

851853
const batchResults = await Promise.allSettled(detailPromises);
854+
await rpcDelay(); // Throttle between batches
852855
for (const r of batchResults) {
853856
if (r.status === 'fulfilled' && r.value) {
854857
results.push(r.value);
@@ -997,6 +1000,7 @@ async function fetchUSDCSOLHistory(
9971000
});
9981001

9991002
const batchResults = await Promise.allSettled(detailPromises);
1003+
await rpcDelay(); // Throttle between batches
10001004
for (const r of batchResults) {
10011005
if (r.status === 'fulfilled' && r.value) {
10021006
results.push(r.value);
@@ -1656,6 +1660,7 @@ async function fetchUSDTSOLHistory(
16561660
});
16571661

16581662
const batchResults = await Promise.allSettled(detailPromises);
1663+
await rpcDelay(); // Throttle between batches
16591664
for (const r of batchResults) {
16601665
if (r.status === 'fulfilled' && r.value) {
16611666
results.push(r.value);

0 commit comments

Comments
 (0)