Skip to main content
MetaMask is one of the most popular Ethereum wallets, and OnchainTestKit provides comprehensive support for automating MetaMask interactions in your tests.

MetaMask-Specific Actions

In addition to the common wallet actions, MetaMask supports these specific actions:

Account Management

Add New Account

Create additional accounts in MetaMask:

Switch Between Accounts

Remove Account

Complete Account Management Example

Network Management

Add Custom Network

Add a custom network to MetaMask:

Approve Network Addition

When a dApp requests to add a network:

Network Switching

Switch to a specific network with testnet detection:

Token Management

Add Custom Token

Add ERC-20 tokens to MetaMask:

Token Management Example

MetaMask Configuration

Basic Configuration

Advanced Configuration with Custom Setup

Complete MetaMask Test Example

Here’s a comprehensive example demonstrating various MetaMask features:

Best Practices

When adding networks, always include the chainId to ensure proper network identification
Account removal is permanent within the test context. Plan your test flow accordingly
MetaMask automatically saves state between actions, so network and token additions persist throughout the test

Next Steps