Skip to main content

NetworkEnablementController Actions

12 actions registered.

NameDeprecated
disableNetwork
enableAllPopularNetworks
enableNetwork
enableNetworkInNamespace
getState
init
initNativeAssetIdentifiers
isNetworkEnabled
listPopularEvmNetworks
listPopularMultichainNetworks
listPopularNetworks
restoreEnabledNetworkMap

NetworkEnablementController:disableNetwork​

Package: @metamask/network-enablement-controller

Disables a network for the user.

This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID (for any blockchain network). The method will automatically convert Hex chain IDs to CAIP-2 format internally.

Note: This method will prevent disabling the last remaining enabled network to ensure at least one network is always available.

Parameters:

NameDescription
chainIdThe chain ID of the network to disable. Can be either: - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)

Handler signature:

(chainId: Hex | CaipChainId) => void

NetworkEnablementController:enableAllPopularNetworks​

Package: @metamask/network-enablement-controller

Enables all popular networks and Solana mainnet.

This method first disables all networks across all namespaces, then enables all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and Bitcoin mainnet. This provides exclusive behavior - only popular networks will be enabled after calling this method.

Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.

Handler signature:

() => void

NetworkEnablementController:enableNetwork​

Package: @metamask/network-enablement-controller

Enables or disables a network for the user.

This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID (for any blockchain network). The method will automatically convert Hex chain IDs to CAIP-2 format internally. This dual parameter support allows for backward compatibility with existing EVM chain ID formats while supporting newer multi-chain standards.

When enabling a non-popular network, this method will disable all other networks to ensure only one network is active at a time (exclusive mode).

Parameters:

NameDescription
chainIdThe chain ID of the network to enable or disable. Can be either: - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)

Handler signature:

(chainId: Hex | CaipChainId) => void

NetworkEnablementController:enableNetworkInNamespace​

Package: @metamask/network-enablement-controller

Enables a network for the user within a specific namespace.

This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID (for any blockchain network) and enables it within the specified namespace. The method validates that the chainId belongs to the specified namespace for safety.

Before enabling the target network, this method disables all other networks in the same namespace to ensure exclusive behavior within the namespace.

Parameters:

NameDescription
chainIdThe chain ID of the network to enable. Can be either: - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
namespaceThe CAIP namespace where the network should be enabled

Handler signature:

(chainId: Hex | CaipChainId, namespace: CaipNamespace) => void

NetworkEnablementController:getState​

Package: @metamask/network-enablement-controller

Handler signature:

() => NetworkEnablementControllerState

NetworkEnablementController:init​

Package: @metamask/network-enablement-controller

Initializes the network enablement state from network controller configurations.

This method reads the current network configurations from both NetworkController and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly. It ensures proper namespace buckets exist for all configured networks and only adds missing networks with a default value of false, preserving existing user settings.

This method should be called after the NetworkController and MultichainNetworkController have been initialized and their configurations are available.

Handler signature:

() => Promise<void>

NetworkEnablementController:initNativeAssetIdentifiers​

Package: @metamask/network-enablement-controller

Initializes the native asset identifiers from network configurations. This method should be called from the client during controller initialization to populate the nativeAssetIdentifiers state based on actual network configurations.

Parameters:

NameDescription
networksArray of network configurations with chainId and nativeCurrency

Handler signature:

(networks: NetworkConfig[]) => Promise<void>

NetworkEnablementController:isNetworkEnabled​

Package: @metamask/network-enablement-controller

Checks if a network is enabled.

Parameters:

NameDescription
chainIdThe chain ID of the network to check. Can be either: - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)

Returns: True if the network is enabled, false otherwise

Handler signature:

(chainId: Hex | CaipChainId) => boolean

NetworkEnablementController:listPopularEvmNetworks​

Package: @metamask/network-enablement-controller

Returns popular EVM network chain IDs in hex form, restricted to networks that exist in NetworkController (networkConfigurationsByChainId). Source is the bundled POPULAR_NETWORKS unioned with registry-featured EVM chains.

Returns: Hex chain IDs for popular EVM networks that are configured.

Handler signature:

() => Hex[]

NetworkEnablementController:listPopularMultichainNetworks​

Package: @metamask/network-enablement-controller

Returns popular multichain (Bitcoin, Solana, Tron, Stellar) mainnet chain IDs in CAIP-2 form, restricted to networks that exist in MultichainNetworkController (multichainNetworkConfigurationsByChainId).

Returns: CAIP-2 chain IDs for Bitcoin, Solana, Tron, and Stellar mainnets that are configured.

Handler signature:

() => CaipChainId[]

NetworkEnablementController:listPopularNetworks​

Package: @metamask/network-enablement-controller

Returns the list of popular network chain IDs in CAIP-2 form, restricted to networks that exist in NetworkController (networkConfigurationsByChainId) and MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin, Solana, Tron, and Stellar mainnets.

Returns: CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.

Handler signature:

() => CaipChainId[]

NetworkEnablementController:restoreEnabledNetworkMap​

Package: @metamask/network-enablement-controller

Restores the enabled network map to a previously snapshotted state.

Not a general merge API: only updates keys already present in the current map. Missing snapshot values default to false. Intended for callers with direct controller access (e.g. extension) to undo #onAddNetwork filter switches when adding a network without changing the active selection. Networks not in the snapshot keep their current value if every network enabled in the snapshot is still enabled; otherwise they are disabled.

Parameters:

NameDescription
enabledNetworkMapPreviously snapshotted enabledNetworkMap.

Handler signature:

(enabledNetworkMap: NetworkEnablementControllerState['enabledNetworkMap']) => void