I’ve been speaking to Kresimir about an issue we’re seeing on our account: we frequently get rate limit responses when we call the Moralis API:
Error: This Moralis Server is rate-limited because of the plan restrictions. See the details about the current rate and throttle limits: {}
But Kresimir asked engineering to look at our account, and they didn’t report seeing any rate-limiting on our account! Can you let me know if this descrepancy is on our side or on yours?
This is an example of how we’re detecting rate limit responses:
async function rateLimit<T>(cb: () => Promise<T>): Promise<T> {
try {
if (Date.now() - rateLimitedAt < 120 * 1000) {
throw new Error('Moralis rate limit has been hit, skipping request.');
}
return await cb();
} catch (err) {
if (
`${err}`.includes('Could not fetch keys') ||
`${err}`.includes('Moralis Server is rate-limited')
) {
rateLimitedAt = Date.now();
}
throw err;
}
}
export const loadTokenBalancesFor = async (wallet: Wallet) => {
const tokenBalances = await rateLimit(async () => {
return await Moralis.Web3API.account.getTokenBalances({
chain: 'eth',
address: wallet.publicKey,
});
});
return tokenBalances.map(b => ({
communityAddress: b.token_address,
tokenBalance: Number(applyDecimals(b.balance, b.decimals)),
}));
};