### bootstrap - Initialize Wallet and Browser Source: https://context7.com/tenkeylabs/dappwright/llms.txt Initializes a browser context with a pre-configured wallet extension, handling installation and setup automatically. ```APIDOC ## bootstrap(seed, options) ### Description Launches a Chromium browser with a specified wallet extension (e.g., MetaMask) installed and configured using a provided seed phrase. ### Parameters #### Path Parameters - **seed** (string) - Required - The 12-24 word seed phrase to initialize the wallet. #### Options - **wallet** (string) - Required - Wallet type (e.g., 'metamask'). - **version** (string) - Required - Version of the wallet extension. - **password** (string) - Required - Password to secure the wallet. - **headless** (boolean) - Optional - Whether to run the browser in headless mode. ### Request Example await bootstrap('test test test...', { wallet: 'metamask', version: '10.0.0', password: 'password123' }); ### Response Returns an array containing [wallet instance, page object, browser context]. ``` -------------------------------- ### Quick Setup with Hardhat and MetaMask Source: https://github.com/tenkeylabs/dappwright/blob/main/README.md Demonstrates a quick setup for testing dApps with Hardhat, Playwright, and MetaMask. It includes bootstrapping the wallet, connecting to the dApp, and switching networks. ```typescript # test.spec.ts import { test as base, expect } from '@playwright/test'; import { BrowserContext } from 'playwright-core'; import { bootstrap, Dappwright, getWallet, MetaMaskWallet } from '@tenkeylabs/dappwright'; export const test = base.extend<{ wallet: Dappwright }, { walletContext: BrowserContext }>({ walletContext: [ async ({}, use) => { // Launch context with extension const [wallet, _, context] = await bootstrap("", { wallet: "metamask", version: MetaMaskWallet.recommendedVersion, seed: "test test test test test test test test test test test junk", // Hardhat's default https://hardhat.org/hardhat-network/docs/reference#accounts headless: false, }); await use(context); await context.close(); }, { scope: 'worker' }, ], context: async ({ walletContext }, use) => { await use(walletContext); }, wallet: async ({ walletContext }, use) => { const wallet = await getWallet("metamask", walletContext); await use(wallet); }, }); test.beforeEach(async ({ page }) => { await page.goto("http://localhost:8080"); }); test("should be able to connect", async ({ wallet, page }) => { await page.click("#connect-button"); await wallet.approve(); const connectStatus = page.getByTestId("connect-status"); await expect(connectStatus).toHaveValue("connected"); await page.click("#switch-network-button"); const networkStatus = page.getByTestId("network-status"); await expect(networkStatus).toHaveValue("31337"); }); ``` -------------------------------- ### Setup and Bootstrap dAppwright Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Configures the MetaMask extension with seed phrases and passwords, or bootstraps the entire environment including launching and setup in one call. ```typescript interface MetamaskOptions { seed?: string; password?: string; showTestNets?: boolean; } // Setup existing browser context await dappwright.setupMetamask(browserContext, { seed: '...' }); // Full bootstrap const [metamask, page, browser] = await dappwright.bootstrap(puppeteer, { metamaskVersion: 'latest' }); ``` -------------------------------- ### dappwright.launch Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Launches a browser instance with the MetaMask extension installed. ```APIDOC ## POST /dappwright/launch ### Description Launches a Playwright browser instance and automatically installs the MetaMask extension. ### Method POST ### Endpoint dappwright.launch(browserName, options) ### Parameters #### Path Parameters - **browserName** (string) - Required - The name of the browser to launch (e.g., 'chromium'). #### Request Body - **options** (OfficialOptions | CustomOptions) - Required - Configuration for MetaMask version or local path. ### Response #### Success Response (200) - **browser** (Browser) - An instance of a Playwright browser. ``` -------------------------------- ### Launch dAppwright Browser Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Initializes a browser instance with the MetaMask extension installed. It accepts either official versioning or a custom path to the extension. ```typescript interface OfficialOptions { metamaskVersion: 'latest' | string; metamaskLocation?: Path; } type Path = string | { download: string; extract: string }; interface CustomOptions { metamaskPath: string; } await dappwright.launch('chromium', { metamaskVersion: 'latest' }); ``` -------------------------------- ### Launch Custom Browser Context with Wallet Source: https://context7.com/tenkeylabs/dappwright/llms.txt Provides lower-level control for launching a browser with a wallet extension. Useful for scenarios requiring custom setup steps or additional browser extensions. ```typescript import { launch, getWallet, MetaMaskWallet } from '@tenkeylabs/dappwright'; async function customSetup() { const { wallet, browserContext } = await launch('', { wallet: 'metamask', version: MetaMaskWallet.recommendedVersion, headless: false, additionalExtensions: ['/path/to/other/extension'], }); await wallet.setup({ seed: 'your twelve word seed phrase goes here for testing', password: 'securePassword123!', showTestNets: true, }); const configuredWallet = await getWallet('metamask', browserContext); return { wallet: configuredWallet, browserContext }; } ``` -------------------------------- ### launch - Custom Browser Launch Source: https://context7.com/tenkeylabs/dappwright/llms.txt Provides low-level control to launch a browser with a wallet extension without automatic setup, allowing for custom configuration steps. ```APIDOC ## launch(seed, options) ### Description Launches the browser context with the wallet extension installed, returning the instance for manual configuration via the `wallet.setup()` method. ### Parameters - **wallet** (string) - Required - The wallet identifier. - **additionalExtensions** (array) - Optional - Paths to additional browser extensions to load. ### Request Example const { wallet, browserContext } = await launch('', { wallet: 'metamask', headless: false }); ### Response Returns an object containing { wallet, browserContext }. ``` -------------------------------- ### Playwright Configuration for Multi-Wallet Setup (JavaScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Configures Playwright to test dApps with multiple wallet types (MetaMask, Coinbase Wallet) by defining separate project configurations. Each project specifies wallet metadata, including version and seed phrases. This setup allows for parallel testing across different wallet environments. ```javascript import { defineConfig } from '@playwright/test'; import { CoinbaseWallet, MetaMaskWallet } from '@tenkeylabs/dappwright'; export default defineConfig({ testIgnore: '**/*.test.ts', retries: process.env.CI ? 1 : 0, timeout: process.env.CI ? 120000 : 60000, use: { trace: process.env.CI ? 'retain-on-first-failure' : 'on', headless: false, }, reporter: [['list'], ['html', { open: 'on-failure' }]], webServer: { command: 'npm run dev', url: 'http://localhost:3000', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, }, projects: [ { name: 'MetaMask', metadata: { wallet: 'metamask', version: MetaMaskWallet.recommendedVersion, seed: 'test test test test test test test test test test test junk', password: 'password1234!@#$' }, }, { name: 'Coinbase', metadata: { wallet: 'coinbase', version: CoinbaseWallet.recommendedVersion, seed: 'test test test test test test test test test test test junk', password: 'password1234!@#$' }, }, ], }); ``` -------------------------------- ### ImportPK - Import Account from Private Key (TypeScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Imports an existing account into the wallet using its private key via the `importPK` method. This is useful for testing with pre-funded accounts. The examples cover successful import, and expected failures with invalid or duplicate private keys. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('import account from private key', async ({ wallet }: { wallet: Dappwright }) => { // Import a Hardhat default account await wallet.importPK('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); // Account should now be available await expect(wallet.page.getByText('Imported Account')).toBeVisible(); }); test('import fails with invalid key', async ({ wallet }: { wallet: Dappwright }) => { // Invalid private key should throw await expect( wallet.importPK('invalid-key') ).rejects.toThrow(); }); test('import fails with duplicate key', async ({ wallet }: { wallet: Dappwright }) => { const privateKey = '4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b10'; // First import succeeds await wallet.importPK(privateKey); // Second import should fail (duplicate) await expect(wallet.importPK(privateKey)).rejects.toThrow(); }); ``` -------------------------------- ### Bootstrap Playwright Test Environment with Wallet Source: https://context7.com/tenkeylabs/dappwright/llms.txt Initializes a Playwright test environment with a pre-configured wallet extension. This setup uses a worker-scoped fixture to manage the browser context and wallet instance efficiently across tests. ```typescript import { test as base, expect } from '@playwright/test'; import { BrowserContext } from 'playwright-core'; import { bootstrap, Dappwright, getWallet, MetaMaskWallet } from '@tenkeylabs/dappwright'; export const test = base.extend<{ wallet: Dappwright }, { walletContext: BrowserContext }>({ walletContext: [ async ({}, use) => { const [wallet, page, context] = await bootstrap('', { wallet: 'metamask', version: MetaMaskWallet.recommendedVersion, seed: 'test test test test test test test test test test test junk', password: 'password1234!@#$', headless: false, }); await use(context); await context.close(); }, { scope: 'worker' }, ], context: async ({ walletContext }, use) => { await use(walletContext); }, wallet: async ({ walletContext }, use) => { const wallet = await getWallet('metamask', walletContext); await use(wallet); }, }); test('should connect to dApp', async ({ wallet, page }) => { await page.goto('http://localhost:8080'); await page.click('#connect-button'); await wallet.approve(); await expect(page.locator('#connected')).toBeVisible(); }); ``` -------------------------------- ### Install dAppwright using npm or yarn Source: https://github.com/tenkeylabs/dappwright/blob/main/README.md Installs the dAppwright package as a dependency for your project. This package provides the necessary tools for integrating Playwright with browser wallets. ```bash npm install -s @tenkeylabs/dappwright yarn add @tenkeylabs/dappwright ``` -------------------------------- ### CreateAccount - Create New Wallet Account (TypeScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Creates a new account or address within the wallet using the `createAccount` method. An optional custom name can be provided for the account. The examples demonstrate creating a single account with a name and creating multiple accounts sequentially. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('create new account', async ({ wallet }: { wallet: Dappwright }) => { // Create account with custom name await wallet.createAccount('Trading Account'); // Verify account was created await expect(wallet.page.getByText('Trading Account')).toBeVisible(); }); test('create multiple accounts', async ({ wallet }: { wallet: Dappwright }) => { await wallet.createAccount('Account A'); await wallet.createAccount('Account B'); await wallet.createAccount('Account C'); }); ``` -------------------------------- ### Retrieve Token Balances Source: https://context7.com/tenkeylabs/dappwright/llms.txt Retrieves the balance of a specific token by its symbol. Includes examples for verifying balance changes after transactions and handling errors for non-existent tokens. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('get token balance', async ({ wallet }: { wallet: Dappwright }) => { const ethBalance = await wallet.getTokenBalance('ETH'); expect(ethBalance).toBeGreaterThanOrEqual(0); }); test('verify balance after transfer', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { const initialBalance = await wallet.getTokenBalance('GO'); await page.goto('https://your-dapp.com'); await page.click('.connect-button'); await wallet.approve(); await page.click('.transfer-button'); await wallet.confirmTransaction(); const finalBalance = await wallet.getTokenBalance('GO'); expect(finalBalance).toBeLessThan(initialBalance); }); test('token not found throws error', async ({ wallet }: { wallet: Dappwright }) => { await expect(wallet.getTokenBalance('NONEXISTENT')).rejects.toThrow('Token NONEXISTENT not found'); }); ``` -------------------------------- ### SwitchAccount - Switch Between Wallet Accounts (TypeScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Changes the active account in the wallet using the `switchAccount` method. This method requires the account name as an argument. Examples show switching to a previously created account and a workflow involving switching accounts during a dApp interaction. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('switch between accounts', async ({ wallet }: { wallet: Dappwright }) => { // Create a second account await wallet.createAccount('Secondary Account'); // Switch back to the first account await wallet.switchAccount('Account 1'); await expect(wallet.page.getByText('Account 1')).toBeVisible(); }); test('multi-account workflow', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); // Connect with first account await wallet.switchAccount('Account 1'); await page.click('.connect-button'); await wallet.approve(); // Perform action, then switch accounts await wallet.switchAccount('Account 2'); // The dApp may need to reconnect with new account }); ``` -------------------------------- ### DeleteAccount - Remove Imported Account (TypeScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Removes an imported account from the wallet using the `deleteAccount` method. Note that HD wallet derived accounts cannot typically be deleted, only imported ones. The example demonstrates importing an account and then deleting it. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('delete imported account', async ({ wallet }: { wallet: Dappwright }) => { // Import an account await wallet.importPK('4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b10'); // Delete the imported account await wallet.deleteAccount('Imported Account 1'); }); ``` -------------------------------- ### Sign-In With Ethereum (SIWE) Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `signin` method is specifically designed for Sign-In With Ethereum (SIWE) authentication flows. It handles the complete SIWE signing process in a single call. ```APIDOC ## Sign-In With Ethereum (SIWE) ### Description Handles the complete Sign-In With Ethereum (SIWE) authentication and signing process. ### Method `wallet.signin()` ### Parameters None ### Request Example ```typescript await wallet.signin(); ``` ### Response None. This action simulates the completion of the SIWE authentication flow within the wallet. ``` -------------------------------- ### POST createAccount Source: https://context7.com/tenkeylabs/dappwright/llms.txt Creates a new account within the wallet. ```APIDOC ## POST createAccount ### Description Creates a new account/address within the wallet with an optional custom name. ### Method POST ### Endpoint wallet.createAccount(name) ### Parameters #### Request Body - **name** (string) - Optional - The display name for the new account. ### Request Example await wallet.createAccount('Trading Account'); ### Response #### Success Response (200) - **void** - Returns nothing upon successful account creation. ``` -------------------------------- ### metamask.sign() Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Commands MetaMask to sign a message. Requires MetaMask to be in a sign confirmation state. ```APIDOC ## `metamask.sign(): Promise` ### Description Commands MetaMask to sign a message. For this to work, MetaMask must be in a sign confirmation state. ### Method `sign` ### Endpoint N/A (In-browser JavaScript API) ### Parameters None ### Request Example ```javascript await metamask.sign(); ``` ### Response #### Success Response (void) Indicates the signing process was initiated successfully. #### Response Example (No explicit response body, resolves Promise on success) ``` -------------------------------- ### CI/CD GitHub Actions Configuration for Playwright Tests (YAML) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Sets up a GitHub Actions workflow to run Playwright end-to-end tests in a CI environment. It uses a Docker container with Playwright pre-installed and configures xvfb for virtual display support, which is necessary for browser extensions to function correctly in headless mode. ```yaml name: E2E Tests on: push: branches: [main] pull_request: branches: [main] jobs: e2e: runs-on: ubuntu-latest container: image: mcr.microsoft.com/playwright:v1.56.1-jammy steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' cache: 'npm' - name: Install dependencies run: npm ci - name: Run E2E tests run: xvfb-run --auto-servernum npx playwright test - name: Upload test results uses: actions/upload-artifact@v4 if: always() with: name: playwright-report path: playwright-report/ retention-days: 30 ``` -------------------------------- ### POST importPK Source: https://context7.com/tenkeylabs/dappwright/llms.txt Imports an account using a private key. ```APIDOC ## POST importPK ### Description Imports an existing account into the wallet using its private key. ### Method POST ### Endpoint wallet.importPK(privateKey) ### Parameters #### Request Body - **privateKey** (string) - Required - The hex-encoded private key. ### Request Example await wallet.importPK('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'); ### Response #### Success Response (200) - **void** - Returns nothing upon successful import. ``` -------------------------------- ### Sign-In With Ethereum (SIWE) Authentication with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `signin` method handles the complete Sign-In With Ethereum (SIWE) signing process in a single call, facilitating authentication flows. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('authenticate with SIWE', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); // Initiate SIWE sign-in await page.click('.signin-button'); // Complete SIWE authentication await wallet.signin(); // Verify authenticated state await page.waitForSelector('#signedIn'); await expect(page.locator('.user-profile')).toBeVisible(); }); ``` -------------------------------- ### Manage MetaMask Networks Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Methods to switch between existing networks, add custom networks, or update RPC endpoints for existing ones. ```typescript await metamask.switchNetwork('main'); await metamask.addNetwork({ networkName: 'Polygon', rpc: 'https://polygon-rpc.com', chainId: 137, symbol: 'MATIC' }); await metamask.updateNetworkRpc({ chainId: 1, rpc: 'https://custom-eth-rpc.com' }); ``` -------------------------------- ### Handle Transactions and Tokens Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Automates the process of adding custom tokens to the wallet and confirming pending transactions with optional gas settings. ```typescript await metamask.addToken('0x...'); await metamask.confirmTransaction({ gas: 25, gasLimit: 60000 }); ``` -------------------------------- ### metamask.approve() Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Enables the app to connect to a MetaMask account in privacy mode. ```APIDOC ## `metamask.approve(): Promise` ### Description Enables the app to connect to a MetaMask account in privacy mode. ### Method `approve` ### Endpoint N/A (In-browser JavaScript API) ### Parameters None ### Request Example ```javascript await metamask.approve(); ``` ### Response #### Success Response (void) Indicates the connection approval was successful. #### Response Example (No explicit response body, resolves Promise on success) ``` -------------------------------- ### Approve Wallet Connection Request Source: https://context7.com/tenkeylabs/dappwright/llms.txt Demonstrates how to programmatically approve a wallet connection request triggered by a dApp. This method interacts with the wallet popup to grant access. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('connect wallet to dApp', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await page.click('.connect-wallet-button'); await wallet.approve(); await expect(page.locator('#wallet-connected')).toBeVisible(); await expect(page.locator('#wallet-address')).toContainText('0x'); }); ``` -------------------------------- ### approve - Approve Connection Request Source: https://context7.com/tenkeylabs/dappwright/llms.txt Programmatically clicks the confirmation button in the wallet popup to approve a dApp connection request. ```APIDOC ## wallet.approve() ### Description Handles the wallet popup interaction to approve a connection request initiated by the dApp. ### Method N/A (Method call on wallet instance) ### Parameters None ### Request Example await wallet.approve(); ### Response Returns a promise that resolves when the connection is approved. ``` -------------------------------- ### Switch Between Networks Source: https://context7.com/tenkeylabs/dappwright/llms.txt Changes the active network in the wallet to facilitate multi-chain testing. It allows switching to pre-configured networks or custom networks previously added to the wallet. ```typescript await wallet.switchNetwork('Sepolia'); ``` -------------------------------- ### GitHub Actions CI Configuration for dAppwright Source: https://github.com/tenkeylabs/dappwright/blob/main/README.md Configures a GitHub Actions workflow to run dAppwright tests in a CI environment. It specifies the Ubuntu runner, Playwright container, and uses xvfb-run for headless browser execution. ```yaml jobs: e2e: runs-on: ubuntu-latest container: image: mcr.microsoft.com/playwright:v1.56.1-jammy steps: - uses: actions/checkout@v4 - name: Install dependencies run: npm ci - name: Run tests run: xvfb-run --auto-servernum npx playwright test ``` -------------------------------- ### Add Custom Tokens to Wallet Source: https://context7.com/tenkeylabs/dappwright/llms.txt Shows how to add ERC-20 tokens to the wallet's tracked list using the addToken method. Requires the contract address and optionally supports symbol and decimal configuration. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('add custom token', async ({ wallet }: { wallet: Dappwright }) => { await wallet.addToken({ tokenAddress: '0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa', symbol: 'DAI', decimals: 18, }); }); test('add token with custom symbol', async ({ wallet }: { wallet: Dappwright }) => { await wallet.addToken({ tokenAddress: '0x1234567890123456789012345678901234567890', symbol: 'MYTOKEN', }); }); ``` -------------------------------- ### metamask.addNetwork Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Adds a custom network to the MetaMask extension. ```APIDOC ## POST /metamask/addNetwork ### Description Adds a custom network configuration to MetaMask. ### Method POST ### Endpoint metamask.addNetwork(options) ### Parameters #### Request Body - **networkName** (string) - Required - Name of the network. - **rpc** (string) - Required - RPC URL. - **chainId** (number) - Required - Chain ID. - **symbol** (string) - Required - Currency symbol. ### Response #### Success Response (200) - **void** - Returns nothing upon successful addition. ``` -------------------------------- ### POST switchAccount Source: https://context7.com/tenkeylabs/dappwright/llms.txt Changes the active account in the wallet. ```APIDOC ## POST switchAccount ### Description Changes the active account in the wallet to the specified account name. ### Method POST ### Endpoint wallet.switchAccount(accountName) ### Parameters #### Path Parameters - **accountName** (string) - Required - The name of the account to switch to. ### Request Example await wallet.switchAccount('Account 1'); ### Response #### Success Response (200) - **void** - Returns nothing upon successful switch. ``` -------------------------------- ### metamask.helpers.getTokenBalance() Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Retrieves the balance of a specific token. ```APIDOC ## `metamask.helpers.getTokenBalance(tokenSymbol: string): Promise` ### Description Gets the balance of a specific token. ### Method `getTokenBalance` ### Endpoint N/A (In-browser JavaScript API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const balance = await metamask.helpers.getTokenBalance('ETH'); console.log(balance); ``` ### Response #### Success Response (200) - **balance** (number) - The token balance. #### Response Example ```json { "balance": 1.2345 } ``` ``` -------------------------------- ### metamask.switchAccount Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Switches the active account in the MetaMask extension. ```APIDOC ## POST /metamask/switchAccount ### Description Commands MetaMask to switch to a different account based on its index in the account list. ### Method POST ### Endpoint metamask.switchAccount(accountNumber) ### Parameters #### Request Body - **accountNumber** (number) - Required - The index/position of the account to switch to. ### Response #### Success Response (200) - **void** - Returns nothing upon successful switch. ``` -------------------------------- ### Check Network Configuration with HasNetwork Source: https://context7.com/tenkeylabs/dappwright/llms.txt Verifies if a specific network is already configured in the wallet. Returns a boolean, making it useful for conditional logic to add networks only if they are missing. ```typescript const exists = await wallet.hasNetwork('Ethereum'); expect(exists).toBeTruthy(); ``` -------------------------------- ### Add Custom Network with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt Configures a new network in the wallet extension by providing network details such as name, RPC URL, chain ID, and symbol. This is vital for testing dApps on local, testnet, or custom chains. ```typescript await wallet.addNetwork({ networkName: 'Hardhat Local', rpc: 'http://localhost:8545', chainId: 31337, symbol: 'ETH', }); ``` -------------------------------- ### Manage Wallet Lock State with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt Demonstrates how to programmatically lock and unlock a wallet using the Dappwright API. This is useful for testing session timeouts and secure re-authentication flows. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('lock and unlock wallet', async ({ wallet }: { wallet: Dappwright }) => { await wallet.lock(); await wallet.unlock('password1234!@#$'); }); test('session timeout handling', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await wallet.lock(); await page.click('.transfer-button'); await wallet.unlock('password1234!@#$'); await wallet.confirmTransaction(); }); ``` -------------------------------- ### Access Wallet Page Directly Source: https://context7.com/tenkeylabs/dappwright/llms.txt Utilizes the wallet.page property to perform low-level Playwright interactions on the wallet extension UI. Useful for taking screenshots or waiting for specific UI states. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('access wallet page directly', async ({ wallet }: { wallet: Dappwright }) => { await wallet.page.bringToFront(); await wallet.page.screenshot({ path: 'wallet-state.png' }); const balance = await wallet.page.locator('.balance-display').textContent(); }); test('wait for wallet state', async ({ wallet }: { wallet: Dappwright }) => { await wallet.page.waitForSelector('[data-testid="home-page"]'); await wallet.page.waitForLoadState('networkidle'); }); ``` -------------------------------- ### Sign Messages with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `sign` method approves message signing requests (e.g., personal_sign, signTypedData) in the wallet popup. This is used to test how a dApp handles signed messages. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('sign a message', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await page.click('.connect-button'); await wallet.approve(); // Request message signature from dApp await page.click('.sign-message-button'); // Sign the message in wallet popup await wallet.sign(); // Verify signature was completed await page.waitForSelector('#message-signed'); const signature = await page.locator('#signature-result').textContent(); expect(signature).toMatch(/^0x[a-fA-F0-9]+$/); }); test('sign SIWE message', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); // Sign-In With Ethereum flow await page.click('.sign-siwe-message'); await wallet.sign(); await page.waitForSelector('#siwe-signed'); }); ``` -------------------------------- ### Confirm dApp-Initiated Network Switch Source: https://context7.com/tenkeylabs/dappwright/llms.txt Approves network switch requests triggered by a dApp via the wallet_switchEthereumChain method. This handles the interaction within the wallet popup to confirm the change. ```typescript await page.click('.switch-to-polygon-button'); await wallet.confirmNetworkSwitch(); ``` -------------------------------- ### Reject Wallet Requests Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `reject` method cancels pending wallet requests, including connection requests and transaction confirmations. Use this to test how your dApp handles user rejections. ```APIDOC ## Reject Wallet Requests ### Description Cancels pending wallet requests, such as connection requests and transaction confirmations, to test dApp rejection handling. ### Method `wallet.reject()` ### Parameters None ### Request Example ```typescript await wallet.reject(); ``` ### Response None. This action simulates a user rejection within the wallet interface. ``` -------------------------------- ### metamask.helpers.deleteNetwork() Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Deletes a custom network from MetaMask. ```APIDOC ## `metamask.helpers.deleteNetwork(): Promise` ### Description Deletes a custom network from MetaMask. ### Method `deleteNetwork` ### Endpoint N/A (In-browser JavaScript API) ### Parameters None ### Request Example ```javascript await metamask.helpers.deleteNetwork(); ``` ### Response #### Success Response (void) Indicates the network was deleted successfully. #### Response Example (No explicit response body, resolves Promise on success) ``` -------------------------------- ### metamask.confirmTransaction Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Confirms a pending transaction in MetaMask. ```APIDOC ## POST /metamask/confirmTransaction ### Description Commands MetaMask to submit a transaction when in a confirmation state. ### Method POST ### Endpoint metamask.confirmTransaction(options) ### Parameters #### Request Body - **gas** (number) - Optional - Gas price. - **gasLimit** (number) - Optional - Gas limit. - **priority** (number) - Optional - Transaction priority. ### Response #### Success Response (200) - **void** - Returns nothing upon successful confirmation. ``` -------------------------------- ### DeleteNetwork - Remove Network Configuration (TypeScript) Source: https://context7.com/tenkeylabs/dappwright/llms.txt Removes a custom network from the wallet configuration using the `deleteNetwork` method. Built-in networks are typically not deletable. This function takes the network name as input and verifies its removal. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('delete custom network', async ({ wallet }: { wallet: Dappwright }) => { const networkName = 'Temporary Testnet'; // Add a network await wallet.addNetwork({ networkName: networkName, rpc: 'https://temp-rpc.example.com', chainId: 99999, symbol: 'TMP', }); expect(await wallet.hasNetwork(networkName)).toBeTruthy(); // Remove the network await wallet.deleteNetwork(networkName); expect(await wallet.hasNetwork(networkName)).toBeFalsy(); }); ``` -------------------------------- ### Sign Messages Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `sign` method confirms message signing requests. When a dApp requests a signature (personal_sign, signTypedData, etc.), this method approves the signature in the wallet popup. ```APIDOC ## Sign Messages ### Description Approves message signing requests initiated by a dApp, such as `personal_sign` or `signTypedData`. ### Method `wallet.sign()` ### Parameters None ### Request Example ```typescript await wallet.sign(); ``` ### Response None. This action simulates user approval of a message signature within the wallet interface. ``` -------------------------------- ### Reject Wallet Requests with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `reject` method cancels pending wallet requests, such as connection requests and transaction confirmations. This is useful for testing how a dApp handles user rejections. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('handle connection rejection gracefully', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); // Initiate connection await page.click('.connect-wallet-button'); // User rejects the connection await wallet.reject(); // Verify dApp handles rejection await page.waitForSelector('#connect-rejected'); await expect(page.locator('.error-message')).toContainText('Connection rejected'); }); test('handle transaction rejection', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await page.click('.connect-wallet-button'); await wallet.approve(); // Initiate a transaction await page.click('.transfer-button'); // Reject the transaction await wallet.reject(); // Verify rejection is handled await page.waitForSelector('#transfer-rejected'); }); ``` -------------------------------- ### DELETE deleteNetwork Source: https://context7.com/tenkeylabs/dappwright/llms.txt Removes a custom network configuration from the wallet. ```APIDOC ## DELETE deleteNetwork ### Description Removes a custom network from the wallet configuration. Built-in networks cannot be deleted. ### Method DELETE ### Endpoint wallet.deleteNetwork(networkName) ### Parameters #### Path Parameters - **networkName** (string) - Required - The name of the network to remove. ### Request Example await wallet.deleteNetwork('Temporary Testnet'); ### Response #### Success Response (200) - **void** - Returns nothing upon successful deletion. ``` -------------------------------- ### metamask.helpers.deleteAccount() Source: https://github.com/tenkeylabs/dappwright/blob/main/docs/API.md Deletes an account by its number. ```APIDOC ## `metamask.helpers.deleteAccount(accountNumber: number): Promise` ### Description Deletes an account containing a name with the specified number. ### Method `deleteAccount` ### Endpoint N/A (In-browser JavaScript API) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters - **accountNumber** (number) - Required - The number of the account to delete. ### Request Example ```javascript await metamask.helpers.deleteAccount(1); ``` ### Response #### Success Response (void) Indicates the account was deleted successfully. #### Response Example (No explicit response body, resolves Promise on success) ``` -------------------------------- ### DELETE deleteAccount Source: https://context7.com/tenkeylabs/dappwright/llms.txt Removes an imported account from the wallet. ```APIDOC ## DELETE deleteAccount ### Description Removes an imported account from the wallet. HD wallet derived accounts cannot be deleted. ### Method DELETE ### Endpoint wallet.deleteAccount(accountName) ### Parameters #### Path Parameters - **accountName** (string) - Required - The name of the imported account to remove. ### Request Example await wallet.deleteAccount('Imported Account 1'); ### Response #### Success Response (200) - **void** - Returns nothing upon successful deletion. ``` -------------------------------- ### Confirm Blockchain Transactions Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `confirmTransaction` method approves pending transactions in the wallet. You can optionally specify custom gas settings including max base fee, priority fee, and gas limit. ```APIDOC ## Confirm Blockchain Transactions ### Description Approves pending blockchain transactions. Allows for optional custom gas settings. ### Method `wallet.confirmTransaction(options?: { gas?: number; priority?: number; gasLimit?: number })` ### Parameters #### Optional Parameters - **gas** (number) - The maximum base fee in Gwei. - **priority** (number) - The priority fee in Gwei. - **gasLimit** (number) - A custom gas limit. ### Request Example (Default Gas) ```typescript await wallet.confirmTransaction(); ``` ### Request Example (Custom Gas) ```typescript await wallet.confirmTransaction({ gas: 4, priority: 3, gasLimit: 202020, }); ``` ### Response None. This action simulates user approval of a transaction within the wallet interface. ``` -------------------------------- ### Confirm Blockchain Transactions with Dappwright Source: https://context7.com/tenkeylabs/dappwright/llms.txt The `confirmTransaction` method approves pending transactions in the wallet. It allows for optional custom gas settings, including max base fee, priority fee, and gas limit. ```typescript import { test, expect } from '@playwright/test'; import { Dappwright } from '@tenkeylabs/dappwright'; test('confirm transaction with default gas', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await page.click('.connect-button'); await wallet.approve(); // Trigger a transaction (e.g., token transfer) await page.click('.transfer-button'); // Confirm with default gas settings await wallet.confirmTransaction(); await page.waitForSelector('#transferred'); }); test('confirm transaction with custom gas', async ({ wallet, page }: { wallet: Dappwright; page: any }) => { await page.goto('https://your-dapp.com'); await page.click('.connect-button'); await wallet.approve(); // Trigger a contract interaction await page.click('.increment-counter'); // Confirm with custom gas settings await wallet.confirmTransaction({ gas: 4, // Max base fee in Gwei priority: 3, // Priority fee in Gwei gasLimit: 202020, // Custom gas limit }); await page.waitForSelector('#counter-incremented'); }); ``` -------------------------------- ### Update Network RPC URL Source: https://context7.com/tenkeylabs/dappwright/llms.txt Modifies the RPC endpoint for an existing network configuration identified by its chain ID. Useful for switching providers or updating local development endpoints. ```typescript await wallet.updateNetworkRpc({ chainId: 1, rpc: 'https://eth-mainnet.alchemyapi.io/v2/your-api-key', }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.