[solved] MoralisError [Moralis SDK Core Error]: [C0006] Request failed: timeout of 20000ms exceeded

I was following a tutorial on Moralis about building a web3 version of PayPal (https://youtu.be/IwfIxAJiNiw). And I run into this error when trying to get the user balance.

I run into this error before when getting the name of the user but it went away after retrying the same request. So I think it could be an issue on Moralis’ side.

Here is where I think the error is coming from:

app.get("/getNameAndBalance", async (req, res) => {
  const { userAddress } = req.query;
  const response = await Moralis.EvmApi.utils.runContractFunction({
    chain: "0x13881",
    address: "0x0dc3eeb267e3fB875c49a2D137779f4574855d01",
    functionName: "getName",
    abi: ABI,
    params: { _user: userAddress },
  });

  const jsonResponseName = response.raw;

  const secondResponse = await Moralis.EvmApi.balance.getNativeBalance({
    chain: "0x13881",
    address: userAddress,
  });

  const jsonResponseBal = (secondResponse.raw.balance / 1e18).toFixed(2);

  const thirdResponse = await Moralis.EvmApi.token.getTokenPrice({
    address: "0x7D1AfA7B718fb89edB30A3aBc0Cfc608AaCfeBB0",
  });

  const jsonResponseDollars = (
    thirdResponse.raw.usdPrice * jsonResponseBal
  ).toFixed(2);

  const jsonResponse = {
    name: jsonResponseName,
    balance: jsonResponseBal,
    dollars: jsonResponseDollarsm,
  };

  return res.status(200).json({ jsonResponse });
});

Here is the error:

/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1217
        return new CoreError({
               ^

MoralisError [Moralis SDK Core Error]: [C0006] Request failed: timeout of 20000ms exceeded
    at RequestController.makeError (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1217:16)
    at RequestController.<anonymous> (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1187:38)
    at step (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:81:23)
    at Object.throw (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:62:53)
    at rejected (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:53:65) {
  isMoralisError: true,
  code: 'C0006',
  details: undefined,
  [cause]: AxiosError: timeout of 20000ms exceeded
      at RedirectableRequest.handleRequestTimeout (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/axios/dist/node/axios.cjs:3010:16)
      at RedirectableRequest.emit (node:events:513:28)
      at Timeout.<anonymous> (/Users/fiat/Developer/learn-solidity/payPalStarter/backend/node_modules/follow-redirects/index.js:169:12)
      at listOnTimeout (node:internal/timers:564:17)
      at process.processTimers (node:internal/timers:507:7)

Any help is appreciated.

you get this error every time?

you shouldn’t get this error as the timeout for the api should be 15 seconds

I get this error every time. And yes the timeout is 20 seconds instead of 15 seconds.

I mean that the api timeout will be 15 seconds. Can you check if there is something blocking the connection like a firewall?

I changed the network I was connected to and it worked. Thanks

But I’m still getting an error when trying to get the USD price of MATIC.

'No pools found with enough liquidity, to calculate the price'

what parameter are you using to get that price?

It’s solved now. I was using the wrong address for the MATIC token

Thanks for the help

1 Like