Skip to content

Maksandre/w3wallets

Repository files navigation

w3wallets

License npm version CodeQL Tests

Web3 wallets for Playwright.

This library provides methods for interacting with Web3 wallets using Playwright.

npm install -D w3wallets

Getting Started

MetaMask and Polkadot{.js} wallets are currently supported.

Metamask Logo Polkadot JS Logo

1. Download wallets

npx w3wallets metamask polkadotjs

Short aliases are also supported:

npx w3wallets mm pjs

The unzipped files are stored in the .w3wallets/<wallet-name> directory. Add .w3wallets to .gitignore.

CLI Options
USAGE:
  npx w3wallets [OPTIONS] <targets...>

TARGETS:
  Alias name      Known wallet alias (metamask, polkadotjs)
  Short alias     Short form (mm, pjs)
  Extension ID    32-character Chrome extension ID
  URL             Chrome Web Store URL

OPTIONS:
  -h, --help      Show help message
  -l, --list      List available wallet aliases
  -o, --output    Output directory (default: .w3wallets)
  -f, --force     Force re-download even if already exists
  --debug         Save raw .crx file for debugging

EXAMPLES:
  npx w3wallets metamask                    # Download MetaMask
  npx w3wallets mm pjs                      # Download all wallets (short)
  npx w3wallets --list                      # List available aliases
  npx w3wallets -o ./extensions metamask    # Custom output directory
  npx w3wallets --force mm                  # Force re-download

2. Wrap your fixture with withWallets

Install the required wallets into Chromium using withWallets.

// your-fixture.ts
import { withWallets, metamask, polkadotJS } from "w3wallets";
import { test as base } from "@playwright/test";

export const test = withWallets(base, metamask, polkadotJS);

export { expect } from "@playwright/test";

3. Use the installed wallets in tests

Most commonly, you will use the following methods:

  1. onboard: to set up your wallet
  2. approve: for operations that confirm actions
  3. deny: for actions that reject or cancel operations
import { test, expect } from "./your-fixture";

test("Can connect MetaMask to dApp", async ({ page, metamask }) => {
  const mnemonic =
    "set your seed phrase test test test test test test test junk";

  await metamask.onboard(mnemonic);
  await page.goto("https://your-dapp.com");

  await page.getByRole("button", { name: "Connect Wallet" }).click();
  await metamask.approve();

  await expect(page.getByText("Connected")).toBeVisible();
});

Configuration

Configure library behavior via environment variables:

Variable Description Default
W3WALLETS_ACTION_TIMEOUT Timeout (ms) for all wallet actions (click, fill, navigation, assertions) undefined

Example:

# In .env or CI environment
W3WALLETS_ACTION_TIMEOUT=60000

This only affects w3wallets library code. Your own Playwright configuration remains independent.

About

Web3 wallet automation for Playwright testing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •