Cannot fetch token balances as wallet contains over 2000 tokens

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.

Hi there, im not able to replicate the timeout with the first address.

Ill report the second error to our team

1 Like

What version of the SDK are you using?

  "packages": {
    "": {
      "dependencies": {
        "@moralisweb3/common-evm-utils": "^2.18.4",
        "fs": "^0.0.1-security",
        "moralis": "^2.18.4",
        "web3": "^1.9.0"
      }
    },
    "node_modules/@moralisweb3/api-utils": {
      "version": "2.21.0",
      "resolved": "https://registry.npmjs.org/@moralisweb3/api-utils/-/api-utils-2.21.0.tgz",
      "integrity": "sha512-C0LrVL27h1y9JNqXhldvPqkJutkPd4t15IeuouAFrjeJwTssiF4OgLI/EaHh8mwV80CX9rQVE5BPJHjBXZ61xA==",
      "dependencies": {
        "@moralisweb3/common-core": "^2.21.0",
        "@moralisweb3/common-evm-utils": "^2.21.0",
        "axios": "^1.2.1"
      }
    },

Is this what you are looking for?
Or from node_modules/moralis/package.json:

  "name": "moralis",
  "author": "Moralis",
  "version": "2.21.0",
  "license": "MIT",
  "description": "Moralis SDK for JavaScript and TypeScript",

you could try to retry the request after it fails with this timeout error

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.