This guide explains TheRPC's rate limiting system and provides best practices for managing your API usage.
Rate limits are applied at several levels:
Specific limits depend on your subscription plan. Check your dashboard for current limits.
When you exceed rate limits, you'll receive:
{
"jsonrpc": "2.0",
"error": {
"code": -32029,
"message": "Rate limit exceeded"
},
"id": 1
}
HTTP response will include headers:
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1628696400
async function callWithRetry(method, params, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await makeRequest(method, params);
return response;
} catch (error) {
if (error.code === -32029) {
// Rate limit exceeded
const backoffTime = Math.pow(2, i) * 1000;
await new Promise((resolve) => setTimeout(resolve, backoffTime));
continue;
}
throw error;
}
}
throw new Error('Max retries exceeded');
}
Combine multiple calls into a single request:
[
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "latest"],
"id": 1
},
{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 2
}
]
For real-time data, use eth_subscribe instead of polling.
Monitor your usage through:
function trackApiUsage(response) {
const limits = {
limit: response.headers['X-RateLimit-Limit'],
remaining: response.headers['X-RateLimit-Remaining'],
reset: response.headers['X-RateLimit-Reset'],
};
// Log or monitor usage
console.log(`API calls remaining: ${limits.remaining}/${limits.limit}`);
}
const cache = new Map();
async function getCachedBlockNumber(cacheTime = 5000) {
const cached = cache.get('blockNumber');
if (cached && Date.now() - cached.timestamp < cacheTime) {
return cached.value;
}
const newValue = await web3.eth.getBlockNumber();
cache.set('blockNumber', {
value: newValue,
timestamp: Date.now(),
});
return newValue;
}
Different subscription plans have different limits:
Check the pricing page for detailed plan comparisons.
If you regularly hit rate limits, consider: