1

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 });

rpc.get_info().then(console.log).catch(console.error);

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.

0

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')

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.