5.7.1 Java  Script
5.7.1.1 Types
5.7.1.2 loader.mjs
5.7.1.3 Account Handles
5.7.1.4 Contract Handles
5.7.1.5 Network Utilities
5.7.1.6 Provider Selection
5.7.1.7 Utilities
5.7.1.8 ask.mjs
On this page:
canonicalize  Connector  Mode
get  Connector  Mode
get  Connector
load  Stdlib
unsafe  Allow  Multiple  Stdlibs
5.7.1.2 loader.mjs

The loader.mjs module exports the following functions that might help you write code that is portable to multiple consensus networks.

canonicalizeConnectorMode(string) => string

Expands a connector mode prefix to its full, canonical name. The canonical connector modes are:

getConnectorMode() => string

Returns the canonicalized connector mode, based on the process.env.REACH_CONNECTOR_MODE environment variable. If the variable is missing or empty, it will return the canonicalized form of 'ETH'.

getConnector() => Connector

Returns the first piece of getConnectorMode().

loadStdlib(env) => Promise<stdlib>

Returns a Promise for a standard library based on the provided env string or map. In environments where the Reach standard library has implicit access to process.env, you may omit the env argument, in which case process.env will be used.

If the standard library is being used with JavaScript bundlers like Webpack —as it is with React, for example— then Reach does not have implicit access to process.env. In such scenarios, we recommend that you call this function like so:

const reach = await loadStdlib(process.env);

Or construct a custom object that has all of the environment keys and fields you need.

As a special case, you may instead pass in the string 'ETH' or the string 'ALGO' to select the desired connector directly.

By default, this method allows a user to load a standard library for a single connector. That is, this method may not be called multiple times with varying connectors. To bypass this restriction, use unsafeAllowMultipleStdlibs.

unsafeAllowMultipleStdlibs() => null

Calling this function will lift the restriction that loadStdlib imposes on loading multiple standard libraries.