The script we run monthly keep crashing because for some addresses, it takes too long to fetch the token list (our guess). There are two errors that have the same CODE C0006
.
Error 1:
Error fetching BIRB balance for address 0x9370be8438f08a750add060216908e79d5b3c739: MoralisError [Moralis SDK Core Error]: [C0006] Request failed: timeout of 20000ms exceeded
at RequestController.makeError (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1235:16)
at RequestController.<anonymous> (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1205:38)
at step (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:83:23)
at Object.throw (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:64:53)
at rejected (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:55:65) {
isMoralisError: true,
code: 'C0006',
details: undefined,
[cause]: AxiosError: timeout of 20000ms exceeded
Error 2:
Error fetching BIRB balance for address 0xc4c873dd1ba4d82ef5f96910b9f2bcbee5eabdba: MoralisError [Moralis SDK Core Error]: [C0006] Request failed, Bad Request(400): Cannot fetch token balances as wallet contains over 2000 tokens. Please contact support for further assistance.
at RequestController.makeError (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1224:20)
at RequestController.<anonymous> (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1205:38)
at step (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:83:23)
at Object.throw (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:64:53)
at rejected (/opt/__topsecret/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:55:65)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
isMoralisError: true,
code: 'C0006',
details: {
status: 400,
response: {
status: 400,
statusText: 'Bad Request',
headers: [AxiosHeaders],
config: [Object],
request: [ClientRequest],
data: [Object]
}
},
[cause]: AxiosError: Request failed with status code 400
Our code:
const BIRB = "0x2e8799f0A26d8A9f37a0b4747Fa534f039C2d234";
const CHAIN = EvmChain.BSC;
async function fetchBirbBalance (adr) {
try {
let response = await Moralis.EvmApi.token.getWalletTokenBalances({
"chain": CHAIN,
"tokenAddresses": [BIRB],
"address": adr
});
response = response.toJSON();
if (response && Object.keys(response).length !== 0 ) {
if (typeof response[0].balance !== 'undefined' ) {
return response[0].balance;
}
}
} catch (e) {
console.error('Error fetching BIRB balance for address ' + adr + ':', e);
process.exit(1);
}
return false;
}
Question:
What can we do to allow for a increased timeout or to limit fetching 2000+ tokens? It seems sending the tokenAddresses
along does not help.