Web Utilities

ethers.utils.fetchJson( urlOrConnectionInfo [ , json [ , processFunc ] ] ) Promise< any >

Fetch and parse the JSON content from urlOrConnectionInfo, with the optional body json and optionally processing the result with processFun before returning it.

ethers.utils.poll( pollFunc [ , options ] ) Promise< any >

Repeatedly call pollFunc using the PollOptions until it returns a value other than undefined.

ConnectionInfo

connection.url string

The URL to connect to.

connection.user string

The username to use for Basic Authentication. The default is null (i.e. do not use basic authentication)

connection.password string

The password to use for Basic Authentication. The default is null (i.e. do not use basic authentication)

connection.allowInsecureAuthentication boolean

Allow Basic Authentication over non-secure HTTP. The default is false.

connection.timeout number

How long to wait (in ms) before rejecting with a timeout error. (default: 120000).

connection.headers {[key:string]:string}

Additional headers to include in the connection.

connection.skipFetchSetup boolean

Normally a connection will specify the default values for a connection such as CORS-behavior and caching policy, to ensure compatibility across platforms. On some services, such as Cloudflare Workers, specifying any value (inclluding the default values) will cause failure. Setting this to true will prevent any values being passed to the underlying API.

connection.errorPassThrough boolean

If false, any server error is thrown as a SERVER_ERROR, otherwise a the processFunc is called with response including the error status intact. (default: false)

connection.allowGzip boolean

Allow Gzip responses. (default: false)

connection.throttleLimit boolean

How many times to retry in the event of a 429 status code.

connection.throttleSlotInterval boolean

The exponential back-off slot delay (i.e. omega), creating a staggered, increasing random delay on retries.

connection.throttleCallback boolean

Callback that allows application level hints to retry (within the throttleLimit) or quick fail.

PollOptions

options.timeout number

The amount of time (in ms) allowed to elapse before triggering a timeout error.

options.floor number

The minimum time limit to allow for Exponential Backoff.

The default is 0s.

options.ceiling number

The maximum time limit to allow for Exponential Backoff.

The default is 10s.

options.interval number

The interval used during Exponential Backoff calculation.

The default is 250ms.

options.retryLimit number

The number of times to retry in the event of an error or undefined is returned.

options.onceBlock Provider

If this is specified, the polling will wait on new blocks from provider before attempting the pollFunc again.

options.oncePoll Provider

If this is specified, the polling will occur on each poll cycle of provider before attempting the pollFunc again.