5.7.1 Java  Script
5.7.1.1 Types
5.7.1.2 loader.mjs
5.7.1.3 Accounts
5.7.1.4 Contracts
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:
set  Provider  By  Name
provider  Env  By  Name
set  Provider  By  Env
set  Provider
5.7.1.6 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'

On Algorand, env may include keys: 'ALGO_LEDGER', 'ALGO_SERVER', 'ALGO_PORT', 'ALGO_TOKEN', 'ALGO_INDEXER_SERVER', 'ALGO_INDEXER_PORT', 'ALGO_INDEXER_TOKEN'.

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