
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
@metamask/network-enablement-controller
Advanced tools
Provides an interface to the currently enabled network using a MetaMask-compatible provider object
A MetaMask controller for managing network enablement state across different blockchain networks.
The NetworkEnablementController tracks which networks are enabled/disabled for the user and provides methods to toggle network states. It supports both EVM (EIP-155) and non-EVM networks like Solana.
npm install @metamask/network-enablement-controller
yarn add @metamask/network-enablement-controller
import { NetworkEnablementController } from '@metamask/network-enablement-controller';
// Create controller instance
const controller = new NetworkEnablementController({
messenger,
state: {
enabledNetworkMap: {
eip155: {
'0x1': true, // Ethereum mainnet enabled
'0xa': false, // Optimism disabled
},
solana: {
'solana:mainnet': true,
},
},
},
});
// Enable a network
controller.setEnabledNetwork('0x1'); // Hex format for EVM
controller.setEnabledNetwork('eip155:1'); // CAIP-2 format for EVM
controller.setEnabledNetwork('solana:mainnet'); // CAIP-2 format for Solana
// Disable a network
controller.setDisabledNetwork('0xa');
// Check if network is enabled
const isEnabled = controller.isNetworkEnabled('0x1');
// Get all enabled networks for a namespace
const evmNetworks = controller.getEnabledNetworksForNamespace('eip155');
// Get all enabled networks across all namespaces
const allNetworks = controller.getAllEnabledNetworks();
The controller also provides selectors that can be used in Redux contexts or any state management system:
import {
selectIsNetworkEnabled,
selectAllEnabledNetworks,
selectEnabledNetworksForNamespace,
selectEnabledEvmNetworks,
selectEnabledSolanaNetworks,
} from '@metamask/network-enablement-controller';
// Get controller state
const state = controller.state;
// Check if a specific network is enabled
const isEthereumEnabled = selectIsNetworkEnabled('0x1')(state);
const isSolanaEnabled = selectIsNetworkEnabled('solana:mainnet')(state);
// Get all enabled networks across all namespaces
const allEnabledNetworks = selectAllEnabledNetworks(state);
// Returns: { eip155: ['0x1'], solana: ['solana:mainnet'] }
// Get enabled networks for a specific namespace
const evmNetworks = selectEnabledNetworksForNamespace('eip155')(state);
const solanaNetworks = selectEnabledNetworksForNamespace('solana')(state);
// Convenience selectors for specific network types
const enabledEvmNetworks = selectEnabledEvmNetworks(state);
const enabledSolanaNetworks = selectEnabledSolanaNetworks(state);
// Get total count of enabled networks
const totalEnabled = selectEnabledNetworksCount(state);
// Check if any networks are enabled for a namespace
const hasEvmNetworks = selectHasEnabledNetworksForNamespace('eip155')(state);
setEnabledNetwork(chainId: Hex | CaipChainId): voidEnables a network for the user. Accepts either Hex chain IDs (for EVM networks) or CAIP-2 chain IDs (for any blockchain network).
setDisabledNetwork(chainId: Hex | CaipChainId): voidDisables a network for the user. Prevents disabling the last remaining enabled network.
isNetworkEnabled(chainId: Hex | CaipChainId): booleanChecks if a network is currently enabled. Returns false for unknown networks.
getEnabledNetworksForNamespace(namespace: CaipNamespace): string[]Gets all enabled networks for a specific namespace.
getAllEnabledNetworks(): Record<CaipNamespace, string[]>Gets all enabled networks across all namespaces.
selectIsNetworkEnabled(chainId: Hex | CaipChainId)Returns a selector function that checks if a specific network is enabled.
selectAllEnabledNetworksReturns a selector function that gets all enabled networks across all namespaces.
selectEnabledNetworksForNamespace(namespace: CaipNamespace)Returns a selector function that gets enabled networks for a specific namespace.
selectEnabledNetworksCountReturns a selector function that gets the total count of enabled networks.
selectHasEnabledNetworksForNamespace(namespace: CaipNamespace)Returns a selector function that checks if any networks are enabled for a namespace.
selectEnabledEvmNetworksReturns a selector function that gets all enabled EVM networks.
selectEnabledSolanaNetworksReturns a selector function that gets all enabled Solana networks.
The controller supports two chain ID formats:
'0x1' for Ethereum mainnet)'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)'0x1' or 'eip155:1''0xa' or 'eip155:10''0xa4b1' or 'eip155:42161''solana:mainnet''solana:testnet'The controller state is automatically persisted and restored between sessions. The enabledNetworkMap is stored anonymously to protect user privacy.
FAQs
Provides an interface to the currently enabled network using a MetaMask-compatible provider object
The npm package @metamask/network-enablement-controller receives a total of 53,850 weekly downloads. As such, @metamask/network-enablement-controller popularity was classified as popular.
We found that @metamask/network-enablement-controller demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.