NetworkController Actions
22 actions registered.
NetworkController:addNetwork
Package: @metamask/network-controller
Creates and registers network clients for the collection of Infura and custom RPC endpoints that can be used to make requests for a particular chain, storing the given configuration object in state for later reference.
Parameters:
| Name | Description |
|---|---|
fields | The object that describes the new network/chain and lists the RPC endpoints which front that chain. |
Returns: The newly added network configuration.
Handler signature:
(fields: AddNetworkFields) => NetworkConfiguration
NetworkController:findNetworkClientIdByChainId
Package: @metamask/network-controller
Searches for the default RPC endpoint configured for the given chain and
returns its network client ID. This can then be passed to
getNetworkClientById to retrieve the network client.
Parameters:
| Name | Description |
|---|---|
chainId | Chain ID to search for. |
Returns: The ID of the network client created for the chain's default RPC endpoint.
Handler signature:
(chainId: Hex) => NetworkClientId
NetworkController:get1559CompatibilityWithNetworkClientId
Package: @metamask/network-controller
Handler signature:
(networkClientId: NetworkClientId) => Promise<boolean>
NetworkController:getEIP1559Compatibility
Package: @metamask/network-controller
Determines whether the network supports EIP-1559 by checking whether the
latest block has a baseFeePerGas property, then updates state
appropriately.
Parameters:
| Name | Description |
|---|---|
networkClientId | The networkClientId to fetch the correct provider against which to check 1559 compatibility. |
Returns: A promise that resolves to true if the network supports EIP-1559 , false otherwise, or undefined if unable to determine the compatibility.
Handler signature:
(networkClientId?: NetworkClientId) => Promise<undefined | boolean>
NetworkController:getEthQuery
Package: @metamask/network-controller
Returns the EthQuery instance for the currently selected network.
Returns: The EthQuery instance, or undefined if the provider has not been initialized.
Handler signature:
() => EthQuery | undefined
NetworkController:getNetworkClientById
Package: @metamask/network-controller
Returns the Infura network client with the given ID.
Parameters:
| Name | Description |
|---|---|
infuraNetworkClientId | An Infura network client ID. |
Returns: The Infura network client.
Handler signature:
(infuraNetworkClientId: BuiltInNetworkClientId) => AutoManagedNetworkClient<InfuraNetworkClientConfiguration>
NetworkController:getNetworkClientRegistry
Package: @metamask/network-controller
Internally, the Infura and custom network clients are categorized by type so that when accessing either kind of network client, TypeScript knows which type to assign to the network client. For some cases it's more useful to be able to access network clients by ID instead of by type and then ID, so this function makes that possible.
Returns: The network clients registered so far, keyed by ID.
Handler signature:
() => AutoManagedBuiltInNetworkClientRegistry & AutoManagedCustomNetworkClientRegistry
NetworkController:getNetworkConfigurationByChainId
Package: @metamask/network-controller
Returns the network configuration that has been filed under the given chain ID.
Parameters:
| Name | Description |
|---|---|
chainId | The chain ID to use as a key. |
Returns: The network configuration if one exists, or undefined.
Handler signature:
(chainId: Hex) => NetworkConfiguration | undefined
NetworkController:getNetworkConfigurationByNetworkClientId
Package: @metamask/network-controller
Returns the network configuration that contains an RPC endpoint with the given network client ID.
Parameters:
| Name | Description |
|---|---|
networkClientId | The network client ID to use as a key. |
Returns: The network configuration if one exists, or undefined.
Handler signature:
(networkClientId: NetworkClientId) => NetworkConfiguration | undefined
NetworkController:getProviderAndBlockTracker
Deprecated
Package: @metamask/network-controller
Accesses the provider and block tracker for the currently selected network.
Deprecated: This method has been replaced by getSelectedNetworkClient (which has a more easily used return type) and will be removed in a future release.
Returns: The proxy and block tracker proxies.
Handler signature:
() => {
provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>> | undefined;
blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>> | undefined;
}
NetworkController:getSelectedChainId
Package: @metamask/network-controller
Accesses the chain ID from the selected network client.
Returns: The chain ID of the selected network client in hex format or undefined if there is no network client.
Handler signature:
() => Hex | undefined
NetworkController:getSelectedNetworkClient
Package: @metamask/network-controller
Accesses the provider and block tracker for the currently selected network.
Returns: an object with the provider and block tracker proxies for the currently selected network.
Handler signature:
() => {
provider: SwappableProxy<ProxyWithAccessibleTarget<Provider>>;
blockTracker: SwappableProxy<ProxyWithAccessibleTarget<BlockTracker>>;
} | undefined
NetworkController:getState
Package: @metamask/network-controller
Handler signature:
() => NetworkState
NetworkController:loadBackup
Package: @metamask/network-controller
Merges the given backup data into controller state.
Parameters:
| Name | Description |
|---|---|
backup | The data that has been backed up. |
backup.networkConfigurationsByChainId | Network configurations, keyed by chain ID. |
Handler signature:
({ networkConfigurationsByChainId, }: Pick<NetworkState, 'networkConfigurationsByChainId'>) => void
NetworkController:lookupNetwork
Package: @metamask/network-controller
Uses a request for the latest block to gather the following information on the given or selected network, persisting it to state:
- The connectivity status: whether it is available, geo-blocked (Infura only), unavailable, or unknown
- The capabilities status: whether it supports EIP-1559, whether it does not, or whether it is unknown
Parameters:
| Name | Description |
|---|---|
networkClientId | The ID of the network client to inspect. If no ID is provided, uses the currently selected network. |
Handler signature:
(networkClientId?: NetworkClientId) => Promise<void>
NetworkController:lookupNetworkByClientId
Deprecated
Package: @metamask/network-controller
Uses a request for the latest block to gather the following information on the given network, persisting it to state:
- The connectivity status: whether the network is available, geo-blocked (Infura only), unavailable, or unknown
- The feature compatibility status: whether the network supports EIP-1559,
whether it does not, or whether it is unknown
Deprecated: Please use
lookupNetworkand pass a network client ID instead. This method will be removed in a future major version.
Parameters:
| Name | Description |
|---|---|
networkClientId | The ID of the network client to inspect. |
Handler signature:
(networkClientId: NetworkClientId) => Promise<void>
NetworkController:removeNetwork
Package: @metamask/network-controller
Destroys and unregisters the network identified by the given chain ID, also removing the associated network configuration from state.
Parameters:
| Name | Description |
|---|---|
chainId | The chain ID associated with an existing network. |
Handler signature:
(chainId: Hex) => void
NetworkController:resetConnection
Package: @metamask/network-controller
Ensures that the provider and block tracker proxies are pointed to the currently selected network and refreshes the metadata for the
Handler signature:
() => Promise<void>
NetworkController:rollbackToPreviousProvider
Package: @metamask/network-controller
Assuming that the network has been previously switched, switches to this new network.
If the network has not been previously switched, this method is equivalent
to resetConnection.
Handler signature:
() => Promise<void>
NetworkController:setActiveNetwork
Package: @metamask/network-controller
Changes the selected network.
Parameters:
| Name | Description |
|---|---|
networkClientId | The ID of a network client that will be used to make requests. |
options | Options for this method. |
options.updateState | Allows for updating state. |
Handler signature:
(networkClientId: string, options?: {
updateState?: (state: Draft<NetworkState>) => void;
}) => Promise<void>
NetworkController:setProviderType
Deprecated
Package: @metamask/network-controller
Convenience method to update provider network type settings.
Deprecated: This has been replaced by setActiveNetwork, and will be removed in a future release
Parameters:
| Name | Description |
|---|---|
type | Human readable network name. |
Handler signature:
(type: InfuraNetworkType) => Promise<void>
NetworkController:updateNetwork
Package: @metamask/network-controller
Updates the configuration for a previously stored network filed under the given chain ID, creating + registering new network clients to represent RPC endpoints that have been added and destroying + unregistering existing network clients for RPC endpoints that have been removed.
Note that if chainId is changed, then all network clients associated with
that chain will be removed and re-added, even if none of the RPC endpoints
have changed.
Parameters:
| Name | Description |
|---|---|
chainId | The chain ID associated with an existing network. |
fields | The object that describes the updates to the network/chain, including the new set of RPC endpoints which should front that chain. |
options | Options to provide. |
options.replacementSelectedRpcEndpointIndex | Usually you cannot remove an RPC endpoint that is being represented by the currently selected network client. This option allows you to specify another RPC endpoint (either an existing one or a new one) that should be used to select a new network instead. |
Returns: The updated network configuration.
Handler signature:
(chainId: Hex, fields: UpdateNetworkFields, { replacementSelectedRpcEndpointIndex, }?: {
replacementSelectedRpcEndpointIndex?: number;
}) => Promise<NetworkConfiguration>