Skip to main content

Overview

Wallet instances provide methods to interact with wallet browser extensions. Each wallet type has a specific set of methods tailored to its API.

PolkadotJsWalletInstance

Methods for interacting with the Polkadot-JS extension. Type: PolkadotJsWalletInstance

Properties

extensionId
string
The Chrome extension ID for this wallet instance
type
'polkadot-js'
The wallet type identifier

importMnemonic()

Import an account using a mnemonic seed phrase.
async importMnemonic(options: WalletAccount): Promise<void>
options.seed
string
required
The mnemonic seed phrase (12 or 24 words)
options.name
string
Account name to display in the wallet
options.password
string
Password to encrypt the account
Example:
await wallets['polkadot-js'].importMnemonic({
  seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
  name: 'Test Account',
  password: 'test123',
})

authorize()

Authorize a website to connect to the wallet.
async authorize(): Promise<void>
Example:
// Navigate to your dApp first
await page.goto('http://localhost:3000')

// Click connect button in your dApp
await page.click('button:has-text("Connect Wallet")')

// Authorize in the wallet popup
await wallets['polkadot-js'].authorize()

approveTx()

Approve a transaction in the wallet popup.
async approveTx(options?: { password?: string }): Promise<void>
options.password
string
Account password if the account is encrypted
Example:
// Trigger a transaction in your dApp
await page.click('button:has-text("Send Transaction")')

// Approve it in the wallet
await wallets['polkadot-js'].approveTx({ password: 'test123' })

rejectTx()

Reject a transaction in the wallet popup.
async rejectTx(): Promise<void>
Example:
await page.click('button:has-text("Send Transaction")')
await wallets['polkadot-js'].rejectTx()

TalismanWalletInstance

Methods for interacting with the Talisman extension. Type: TalismanWalletInstance

Properties

extensionId
string
The Chrome extension ID for this wallet instance
type
'talisman'
The wallet type identifier

importPolkadotMnemonic()

Import a Polkadot account using a mnemonic.
async importPolkadotMnemonic(options: WalletAccount): Promise<void>
options.seed
string
required
The mnemonic seed phrase
options.name
string
Account name to display in the wallet
options.password
string
Password to encrypt the account
Example:
await wallets.talisman.importPolkadotMnemonic({
  seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
  name: 'Polkadot Account',
  password: 'test123',
})

importEthPrivateKey()

Import an Ethereum account using a private key.
async importEthPrivateKey(options: {
  privateKey: string
  name?: string
  password?: string
}): Promise<void>
options.privateKey
string
required
The Ethereum private key (with or without 0x prefix)
options.name
string
Account name to display in the wallet
options.password
string
Password to encrypt the account
Example:
await wallets.talisman.importEthPrivateKey({
  privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
  name: 'Ethereum Account',
})

authorize()

Authorize a website to connect to the wallet.
async authorize(options?: { accountName?: string }): Promise<void>
options.accountName
string
Specific account name to authorize. If not provided, uses the most recently imported account.
Example:
await page.goto('http://localhost:3000')
await page.click('button:has-text("Connect Wallet")')
await wallets.talisman.authorize({ accountName: 'Polkadot Account' })

approveTx()

Approve a transaction in the wallet popup.
async approveTx(): Promise<void>
Example:
await page.click('button:has-text("Send Transaction")')
await wallets.talisman.approveTx()

rejectTx()

Reject a transaction in the wallet popup.
async rejectTx(): Promise<void>
Example:
await page.click('button:has-text("Send Transaction")')
await wallets.talisman.rejectTx()

MetaMaskWalletInstance

Methods for interacting with the MetaMask extension. Type: MetaMaskWalletInstance

Properties

extensionId
string
The Chrome extension ID for this wallet instance
type
'metamask'
The wallet type identifier

importSeedPhrase()

Import a wallet using a seed phrase during initial setup.
async importSeedPhrase(options: { seedPhrase: string }): Promise<void>
options.seedPhrase
string
required
The seed phrase to import (12, 15, 18, 21, or 24 words)
Example:
await wallets.metamask.importSeedPhrase({
  seedPhrase: 'test test test test test test test test test test test junk',
})
This method should be called once during the first test in a worker. MetaMask sets a default password of “h3llop0lkadot!” during import.

unlock()

Unlock MetaMask with the default password.
async unlock(): Promise<void>
Example:
// MetaMask locks after some time
await wallets.metamask.unlock()

authorize()

Authorize a website to connect to MetaMask.
async authorize(): Promise<void>
Example:
await page.goto('http://localhost:3000')
await page.click('button:has-text("Connect MetaMask")')
await wallets.metamask.authorize()

confirm()

Confirm a transaction or message signature.
async confirm(): Promise<void>
Example:
// Send a transaction
await page.click('button:has-text("Send ETH")')
await wallets.metamask.confirm()

// Sign a message
await page.click('button:has-text("Sign Message")')
await wallets.metamask.confirm()

reject()

Reject a transaction or message signature.
async reject(): Promise<void>
Example:
await page.click('button:has-text("Send ETH")')
await wallets.metamask.reject()

Type definitions

WalletAccount

interface WalletAccount {
  seed: string
  name?: string
  password?: string
}

WalletTypeMap

interface WalletTypeMap {
  'polkadot-js': PolkadotJsWalletInstance
  'talisman': TalismanWalletInstance
  'metamask': MetaMaskWalletInstance
}

Complete example

import { createWalletTest } from '@avalix/chroma'

const test = createWalletTest()

test('complete Polkadot-JS flow', async ({ page, wallets }) => {
  // 1. Import account
  await wallets['polkadot-js'].importMnemonic({
    seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
    name: 'Test Account',
    password: 'test123',
  })
  
  // 2. Navigate to dApp
  await page.goto('http://localhost:3000')
  
  // 3. Connect wallet
  await page.click('button:has-text("Connect")')
  await wallets['polkadot-js'].authorize()
  
  // 4. Send transaction
  await page.click('button:has-text("Send")')
  await wallets['polkadot-js'].approveTx({ password: 'test123' })
  
  // 5. Verify transaction completed
  await page.waitForSelector('text=Transaction successful')
})

Build docs developers (and LLMs) love