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
The Chrome extension ID for this wallet instance
The wallet type identifier
importMnemonic()
Import an account using a mnemonic seed phrase.
async importMnemonic(options: WalletAccount): Promise<void>
The mnemonic seed phrase (12 or 24 words)
Account name to display in the wallet
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>
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
The Chrome extension ID for this wallet instance
The wallet type identifier
importPolkadotMnemonic()
Import a Polkadot account using a mnemonic.
async importPolkadotMnemonic(options: WalletAccount): Promise<void>
Account name to display in the wallet
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>
The Ethereum private key (with or without 0x prefix)
Account name to display in the wallet
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>
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()
Methods for interacting with the MetaMask extension.
Type: MetaMaskWalletInstance
Properties
The Chrome extension ID for this wallet instance
The wallet type identifier
importSeedPhrase()
Import a wallet using a seed phrase during initial setup.
async importSeedPhrase(options: { seedPhrase: string }): Promise<void>
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
Polkadot-JS
Talisman
MetaMask
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')
})
import { createWalletTest } from '@avalix/chroma'
const test = createWalletTest({
wallets: [{ type: 'talisman' }],
})
test('complete Talisman flow', async ({ page, wallets }) => {
// 1. Import Polkadot account
await wallets.talisman.importPolkadotMnemonic({
seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
name: 'DOT Account',
})
// 2. Import Ethereum account
await wallets.talisman.importEthPrivateKey({
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
name: 'ETH Account',
})
// 3. Connect to dApp
await page.goto('http://localhost:3000')
await page.click('button:has-text("Connect")')
await wallets.talisman.authorize({ accountName: 'DOT Account' })
// 4. Send transaction
await page.click('button:has-text("Send")')
await wallets.talisman.approveTx()
})
import { createWalletTest } from '@avalix/chroma'
const test = createWalletTest({
wallets: [{ type: 'metamask' }],
})
test.beforeAll(async ({ wallets }) => {
// Import seed phrase once per worker
await wallets.metamask.importSeedPhrase({
seedPhrase: 'test test test test test test test test test test test junk',
})
})
test('complete MetaMask flow', async ({ page, wallets }) => {
// 1. Navigate to dApp
await page.goto('http://localhost:3000')
// 2. Connect wallet
await page.click('button:has-text("Connect MetaMask")')
await wallets.metamask.authorize()
// 3. Sign message
await page.click('button:has-text("Sign")')
await wallets.metamask.confirm()
// 4. Send transaction
await page.click('button:has-text("Send ETH")')
await wallets.metamask.confirm()
})