Error [TypeError]: Converting circular structure to JSON

import Moralis from “moralis”;

export default async function handler(req: any, res: any) {
if (req.method !== ‘POST’) {
return res.status(405).send({message: ‘Only POST request are allowed’});
}
if (!Moralis.Core.isStarted) {
await Moralis.start({apiKey: process.env.MORALIS_API_KEY})
}
const address = “0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d”;
const chain = 97;

try {
const response = await Moralis.EvmApi.token.getWalletTokenBalances({
address,
chain,
});
return res.status(200).json({
data: tokens,
});
} catch (e) {
return res.status(500).send({message: e});
}
}

this is my error, people tell me what’s wrong.

  • error Error [TypeError]: Converting circular structure to JSON
    –> starting at object with constructor ‘ClientRequest’
    | property ‘socket’ -> object with constructor ‘TLSSocket’
    — property ‘_httpMessage’ closes the circle
    at JSON.stringify ()
    at sendData (E:\projects\revoke\node_modules\next\dist\server\api-utils\node.js:201:47)
    at ServerResponse.apiRes.send (E:\projects\revoke\node_modules\next\dist\server\api-utils\node.js:444:31)
    at handler (webpack-internal:///(api)/./src/pages/api/moralis/token-wallet.ts:59:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    digest: undefined
    }

It seems like there is no token balance for this wallet on testnet. So it returns an empty response.

Probably the JSON error occured since the code is trying to convert the empty response to json.?

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