I'm trying out the eosjs official documentation, but can't make any RPC calls. This is how I've initialized everything:

const { Api, JsonRpc, RpcError } = require('eosjs');
const { fetch } = require('node-fetch');
const rpc = new JsonRpc('http://jungle2.cryptolions.io:80', { fetch });


I get an error saying:

{ TypeError: f is not a function
    at JsonRpc.<anonymous> (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:99:46)
    at step (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:36:23)
    at Object.next (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:17:53)
    at /home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:11:71
    at new Promise (<anonymous>)
    at __awaiter (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:7:12)
    at JsonRpc.fetch (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:92:16)
    at JsonRpc.<anonymous> (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:208:55)
    at step (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:36:23)
    at Object.next (/home/krtk6160/Desktop/konnectSense/node_modules/eosjs/dist/eosjs-jsonrpc.js:17:53) isFetchError: true }

I've tried with eosjs versions 20.0.0, 20.0.0beta3, 20.0.0beta1 but the error is the same.


The problem was how I was importing the fetch module. I was able to fix the issue by importing the fetch module in the following way:

const fetch = require('fetch')

  • Use 'node-fetch' when fetching from the server (node) and 'fetch' when fetching from the client.
    – Minding
    May 28 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.