5.7.1 Java  Script Types loader.mjs Accounts Contracts Network Utilities Provider Selection Utilities ask.mjs
On this page:
set  Provider  By  Name
provider  Env  By  Name
set  Provider  By  Env
set  Provider Provider Selection

These functions allow you to choose which particular consensus network API provider to connect to.

On Ethereum, if you would like to use the wallet from the user’s browser, the setProvider functions are not needed. The Reach standard library uses window.ethereum by default.

On Algorand, if you would like to use AlgoSigner, the setProvider functions are necessary for all but 'LocalHost'. However, this will eventually become unnecessary. Reach is working with Algorand wallets to develop standards that will put provider selection in control of the end user, instead of the DApp developer.

setProviderByName(string) => void 

Supported provider names are: 'MainNet', 'TestNet', and 'LocalHost'.

On Ethereum, 'MainNet' will connect to homestead, and 'TestNet' to ropsten. Multiple free API providers are used behind the scenes, as implemented by ethers.js.

On Algorand, 'MainNet' will connect to MainNet, and 'TestNet' to TestNet. The free RandLabs API provider is used ( https://algoexplorerapi.io ).

providerEnvByName(string) => env 

Retrieve configuration information about providers by name.

setProviderByEnv(env) => void 

Select an API provider by supplying information about it.

This function’s API is considered unstable.

env is a record with string keys and string values.

On Ethereum, env may include keys: 'ETH_NODE_URI'


'ALGO_LEDGER' is used by AlgoSigner. Configuration for the indicated ledger should match the configuration present in AlgoSigner.

setProvider(provider): void 

Select an API provider by providing an object satisfying its interface.

This function’s API is considered unstable.

On Ethereum, provider is an instance of ethers.provider. See: https://docs.ethers.io/v5/api/providers/provider/

On Algorand, provider is an object:

  ledger: string,
  algodClient: algosdk.Algodv2,
  indexer: algosdk.Indexer,

See: https://algorand.github.io/js-algorand-sdk/