5.7.1 Java  Script Types loader.mjs Account Handles Contract Handles Network Utilities Provider Selection Utilities ask.mjs
On this page:
set  Provider  By  Name
provider  Env  By  Name
set  Provider  By  Env
set  Provider
set  Wallet  Fallback
wallet  Fallback Provider Selection

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

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'


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:

interface Provider {
  algodClient: algosdk.Algodv2,
  indexer: algosdk.Indexer,
  getDefaultAddress: () => Address,
  isIsolatedNetwork: boolean,
  signAndPostTxns: (txns:WalletTransaction[], opts?: any) => Promise<any>,

The algodClient and indexer values are as specified by the Algorand JS SDK. The signAndPostTxns function obeys ARC-0008.

setWalletFallback(make: () => wallet): void

When you call this function, if no browser wallet is available, then make will be called to construct one. The value that make should return differs between connectors.

On Ethereum, it must match the interface of MetaMask. On Conflux, it must match the interface of ConfluxPortal. On Algorand, it must match the ARC-0011 standard.

walletFallback(opts: object): () => wallet

This function returns a value that may be passed to setWalletFallback to synthesize a wallet for use in browsers that do not supply a compliant wallet. Its customization options, opts, depend on the connector.

On Ethereum and Conflux, it always errors and cannot provide a wallet.

On Algorand, it can provide a wallet that directly connects to the Algorand network, like setProviderByName (& setProviderByEnv), but provide interactive signing. The network connection is specified via the providerEnv key, which may be a string (which is used as an argument to providerEnvByName) or an environment (which is used as an argument to setProviderByEnv). By default, signing is via an interactive browser window prompt, where the user repeatedly provides their mnemonic. If the key MyAlgoConnect is provided, and bound to the export of @reach-sh/stdlib/ALGO_MyAlgoConnect, then My Algo will be used for signing. For example, this sets the wallet fallback to be My Algo used with Algorand TestNet:

import MyAlgoConnect from '@reach-sh/stdlib/ALGO_MyAlgoConnect';
  providerEnv: 'TestNet', MyAlgoConnect }));