Converting circular structure to JSON

Hello,

Using:
"moralis": "^2.14.1"
nodejs16

I am calling this methods:

await Moralis.start({
   apiKey: process.env.MORALIS_API_KEY,
});
await Moralis.EvmApi.nft.getWalletNFTs({
   address: username,
   chain: Chains.EvmChain,
});

I get this 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 (<anonymous>)",
        "    at Runtime.module.exports.handler (/var/task/src/handlers/getNFTsMoralisLambda.cjs:56:26)",
        "    at processTicksAndRejections (node:internal/process/task_queues:96:5)"

I canā€™t seem to make this SDK and API work guysā€¦

The import statement fails for me when used within a node module. See my other post: JS SDK ECMAScript import issue

Now the API itself throws this error.

Iā€™m wasting a lot of time compared with youā€™re competition (Alchemy) where itā€™s pretty smooth sailing. Just want to share my honest feeling here.

best

Hey @koxon,

Thanks for reporting :raised_hands:

I wasnā€™t able to replicate your issue there. This API in particular shouldnā€™t have any problem.

However, this is a known issue and the source from experience is the auth.requestMessage API.

On another note, I would like to know further why you are wasting a lot of time and would like to help you further for future improvement. I truly appreciate your honesty and would like to hear your opinion more.

you usually get that error when a function parameter is an object instead of a string

Thanks but Iā€™m not using auth.requestMessage but just

const Moralis = require("moralis").default;
const Chains = require("@moralisweb3/common-evm-utils");

[...]

await Moralis.start({
   apiKey: process.env.MORALIS_API_KEY,
});
await Moralis.EvmApi.nft.getWalletNFTs({
   address: username,
   chain: Chains.EvmChain,
});

Not sure which function youā€™re referring to but my use case is super straight forward as you can see.

I donā€™t know what happens here, you can try to do some debugging, that error in general happens in javascript when the wrong parameters are passed to a function

So if I remove await in front of Moralis.EvmApi.nft.getWalletNFTs it works ā€¦

This works:

output = Moralis.EvmApi.nft.getWalletNFTs({
   address: username,
   chain: Chains.EvmChain,
});

This doesnā€™t work:

output = await Moralis.EvmApi.nft.getWalletNFTs({
   address: username,
   chain: Chains.EvmChain,
});

However the result is empty

Can you do a console log for that username to see if it has the expected value?

Yes itā€™s all good, I even hard coded it. Still empty result.

The call to Moralis is in an Async function (The AWS Lambda handler function):

const Moralis = require("moralis").default;
const Chains = require("@moralisweb3/common-evm-utils");

module.exports.handler = async (event) => {

Then I just call Moralis within a try/catch

try {
       output = Moralis.EvmApi.nft.getWalletNFTs({
            address: '0x9b84b6fe443d57c43c7ff0a2a48650bfee00227b',
            chain: Chains.EvmChain,
        });
}

I tested on x86_64 and arm64. I tested with import (fails) and require.
I will try an older version of the SDK ā€¦

You can also make direct rest http request if you want

So result itā€™s empty because it contains a promise:

RESULT: Promise { <pending> }

So I need that await but then I go back to the JSON issue stated earlier. Just tested with SDK 2.13.0 with the same problem.

I already use the API directly for another demo. I wanted to do a Moralis demo through AWS Lambda but I think Iā€™ll give up ā€¦ Iā€™m wasting too much time :frowning:

Note that I tested in the AWS Lambda environment and locally in a Docker environment simulating AWS Lambda (Using AWS sam local invoke). In both environment it fails.

If anyone made it work in Lambda, please share. And Moralis devs, you should test in AWS Lambda.

Ok looks like the ā€œchainā€ was incorrect.

I started from scratch using the example here:

Now it works. I will try again following my logic.

So check your API Key and Chain because the error messages are not pointing you in the right directions.

1 Like

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