I tried using the SDK for the first time but ran into the following error:
/home/dev/project/node_modules/@mysten/sui.js/dist/cjs/client/http-transport.js:61
throw new Error(
^
Error: The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.
at SuiHTTPTransport.fetch (/home/dev/project/node_modules/@mysten/sui.js/dist/cjs/client/http-transport.js:61:13)
at SuiHTTPTransport.request (/home/dev/project/node_modules/@mysten/sui.js/dist/cjs/client/http-transport.js:69:28)
at RpcModule.getObject (/home/dev/project/node_modules/@mysten/sui.js/dist/cjs/client/client.js:198:33)
at PoolModule.getPool (/home/dev/project/node_modules/@cetusprotocol/cetus-sui-clmm-sdk/dist/index.js:4431:47)
at retrieveAllPositionsOfPool (file:///home/dev/project/src/utils.js:4:41)
at file:///home/dev/project/src/utils.js:15:1
at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
The problem is that the node-fetch module is being used but somehow it is not imported explicitly.
So the easy fix for me was to import node-fetch in my script before importing the Cetus sdk.
I tried using the SDK for the first time but ran into the following error:
I followed the installation instructions and config correctly. However the issue appears to be with the mysten sui sdk https://github.com/MystenLabs/sui/tree/main/sdk/typescript which the cetus sdk uses under the hood.
The problem is that the
node-fetch
module is being used but somehow it is not imported explicitly. So the easy fix for me was to importnode-fetch
in my script before importing the Cetus sdk.Here are general instructions on what I had to do to fix it: https://github.com/node-fetch/node-fetch?tab=readme-ov-file#providing-global-access
So I created a file in my project named
fetch-polyfill.js
And then I adjusted my cetus config to import that file before importing the cetus SDK. Here is how my cetus configuration file looks like now:
If you would like, I can add this to the documentation. I will also open an issue on the mysten sdk.