Skip to main content

MM Connect methods

MM Connect provides several convenience methods for connecting to and interacting with MetaMask, including the following.

connect

Connects to MetaMask and requests account access.

Returns

A promise that resolves to an array of account addresses.

Example

const accounts = await evmClient.connect();
console.log("Connected accounts:", accounts);

connectAndSign

Connects to MetaMask and signs a message in a single operation.

Parameters

  • msg: string - The message to sign.

Returns

A promise that resolves to the signature of the signed message.

Example

const signature = await evmClient.connectAndSign({ 
msg: "Hello from my dapp!"
});
console.log("Signature:", signature);

connectWith

Connects to MetaMask and executes a specific JSON-RPC method.

Parameters

  • rpc: object - The RPC method to execute.
    • method: string - The RPC method name.
    • params: any[] - The parameters for the RPC method.

Returns

A promise that resolves to the result of the RPC call.

Example

const result = await evmClient.connectWith({
rpc: {
method: "eth_getBalance",
params: ["0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6", "latest"]
}
});
console.log("Balance:", result);

getProvider

Returns the active Ethereum provider object.

Returns

The active provider, or undefined if no provider is found.

Example

const provider = evmClient.getProvider();
if (provider) {
// Use the provider for RPC calls
const accounts = await provider.request({
method: "eth_requestAccounts"
});
}

isInitialized

Checks if MM Connect has been initialized.

Returns

True if MM Connect is initialized, false otherwise.

Example

if (evmClient.isInitialized()) {
console.log("SDK is ready to use");
}

terminate

Terminates the MetaMask connection, switching back to the injected provider if connected via extension.

note

The disconnect() SDK method is deprecated. Use terminate() instead.

Example

await evmClient.terminate();
console.log("Connection terminated");