EOSIO/eosjs

How to set timeout, JsonRpc with node-fetch

junha-ahn opened this issue · 3 comments

import { JsonRpc } from 'eosjs'
import fetch from 'node-fetch'

const rpc = new JsonRpc(url, { fetch })  // I can't set anything...
const result = await rpc.get_block(blockHeight)

I want to set timeout.
now I am setting timeout in node_modules dist file

Ah, Actually, I can set right this.

new JsonRpc(url, {
      fetch: (endpoint, options) => {
        return fetch(endpoint, {
          ...options,
          timeout: 1000 * 1
        })
      }
 })

But, Isn't there a better way?

Your second response would be the recommended way to add options to fetch requests through eosjs. The reason why fetch options aren't available at the individual rpc functions is to have clearly defined required arguments for each function. If you need different options for some rpc functions, you can create multiple JsonRpc instances.

I think it's not comfortable. Because I have to check the (eosjs module) code
But OK. Thank you.