Unified entry point for MetaMask Connect SDK packages. This package re-exports both EVM and Multichain functionality from their respective packages for convenient access.
yarn add @metamask/connector
npm install @metamask/connectimport { createEVMClient } from '@metamask/connect/evm';
const client = await createEVMClient({
dapp: {
name: 'My DApp',
url: 'https://mydapp.com',
},
api: {
supportedNetworks: {
'0x1': 'https://mainnet.infura.io/v3/YOUR_KEY',
'0x89': 'https://polygon-mainnet.infura.io/v3/YOUR_KEY',
},
},
});
// Connect to MetaMask
let accounts, chainId;
try {
({ accounts, chainId } = await client.connect({ chainIds: ['0x1'] }));
} catch (error) {
if (error.code === 4001) {
console.log('User rejected the connection request');
} else if (error.code === -32002) {
console.log('Connection request already pending');
}
}
console.log({ accounts }); // The connected accounts where the first account is the selected account
console.log({ chainId }); // The currently active chainId
// Get the EIP-1193 provider
const provider = client.getProvider();
// Make requests
const balance = await provider.request({
method: 'eth_getBalance',
params: [accounts[0], 'latest'],
});Multichain functionality is the package's default export, so import it directly from
@metamask/connect:
import { createMultichainClient } from '@metamask/connect';
const client = await createMultichainClient({
dapp: {
name: 'My DApp',
url: 'https://mydapp.com',
},
api: {
supportedNetworks: {
'eip155:1': 'https://mainnet.infura.io/v3/YOUR_KEY',
// Solana mainnet CAIP-2 ID (first 32 chars of Base58-encoded genesis hash)
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp':
'https://api.mainnet-beta.solana.com',
},
},
});
// Connect with multiple chain scopes
await client.connect(
['eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'],
[],
);
// Invoke methods on specific chains
const result = await client.invokeMethod({
scope: 'eip155:1',
request: {
method: 'eth_blockNumber',
params: [],
},
});This package re-exports all functionality from @metamask/connect-evm:
createEVMClient- Factory function to create an EVM SDK instanceMetamaskConnectEVM- The main EVM SDK classEIP1193Provider- EIP-1193 compliant provider interface keyedgetInfuraRpcUrls- Helper to generate EVM Infura RPC URLs keyed by hex chain ID
See @metamask/connect-evm for detailed API documentation.
This package re-exports all functionality from @metamask/connect-multichain:
createMultichainClient- Factory function to create a Multichain SDK instanceMetaMaskConnectMultichain- The main Multichain SDK classgetInfuraRpcUrls- Helper to generate Infura RPC URLs keyed by CAIP Chain ID- Various domain types, utilities, and error classes
See @metamask/connect-multichain for detailed API documentation.
@metamask/connect → Re-exports from @metamask/connect-multichain (default export)
@metamask/connect/evm → Re-exports from @metamask/connect-evm
These are the only two entry points. There is no
@metamask/connect/multichainsubpath — the multichain API is the default export at@metamask/connect.
| Use Case | Import Path |
|---|---|
| Ethereum/EVM dApps with standard EIP-1193 provider | @metamask/connect/evm |
| Multi-chain dApps (Ethereum + Solana, etc.) | @metamask/connect |
This package is part of a monorepo. Instructions for contributing can be found in the monorepo README.