Nodejs: web workers & Moralis

Hi,

I have implemented a nodeJS server that handles web3 calls (signed by our private key) on a POST request.

As web3 calls can take some time, I’m trying to optimize using web_workers, but am experiencing some issues with the Moralis Object:

await dynamicPool.exec({
task: async (params) => {
try {
await mvSerial_Unlock(params.moralis, params.tokenId, params.passPhrase)

mvSerial_Unlock calls:

await mvMoralis.executeFunction(unlockFunction);

When the exec is triggered, I get an error:

DOMException [DataCloneError]: class Moralis extends _MoralisWeb.default {
/**

  • Call this method to initialize all moralis instances (Mo……
    } could not be cloned.
    at PoolWorker.postMessage (node:internal/worker:341:5)

Moralis is correctly initialized, but it has to be cloned to create a thread, but the error message says I need to call a function, unfortunately the name of the function is truncated.

Does someone what function I need to call ?

Cheers !

Note that the code is working without the thread pool

you are running this server side? in that case you can use directly web3 or ethers to execute a function server side too