# dAppeteer API Methods provided by dAppeteer. For additional information read root [readme](../README.md) - [Launch dAppeteer](#launch) - [Setup MetaMask](#setup) - [Bootstrap dAppeteer](#bootstrap) - [Initialize Snap Environment](#initSnapEnv) - [Get MetaMask Window](#getMetaMask) - [MetaMask methods](#methods) - [switchAccount](#switchAccount) - [importPK](#importPK) - [lock](#lock) - [unlock](#unlock) - [switchNetwork](#switchNetwork) - [acceptAddNetwork](#acceptAddNetwork) - [rejectAddNetwork](#rejectAddNetwork) - [acceptAddToken](#acceptAddToken) - [rejectAddToken](#rejectAddToken) - [confirmTransaction](#confirmTransaction) - [sign](#sign) - [signTypedData](#signTypedData) - [approve](#approve) - [helpers](#helpers) - [getTokenBalance](#getTokenBalance) - [deleteAccount](#deleteAccount) - [deleteNetwork](#deleteNetwork) - [page](#page) - [snaps methods](#snaps-methods) - [installSnap](#installSnap) - [invokeSnap](#invokeSnap) - [getNotificationEmitter](#getNotificationEmitter) - [getAllNotifications](#getAllNotifications) - [dialog](#snapDialog) - [accept](#acceptDialog) - [reject](#rejectDialog) - [type](#typeDialog) # dAppeteer setup methods ## `dappeteer.launch(options: DappeteerLaunchOptions): Promise` ```typescript type DappeteerLaunchOptions = { metaMaskVersion?: | "latest" | "local" | string; metaMaskLocation?: Path; metaMaskPath?: string; metaMaskFlask?: boolean; automation?: "puppeteer" | "playwright"; puppeteerOptions?: Parameters[0]; playwrightOptions?: PlaywrightLaunchOptions; userDataDir?: string; key?: string; }; ``` returns an instance of `DappeteerBrowser` for more information visit [browser page](docs/BROWSER.md) ## `dappeteer.setupMetaMask(browser: Browser, options: MetaMaskOptions = {}, steps: Step[]): Promise` ```typescript interface MetaMaskOptions { seed?: string; password?: string; showTestNets?: boolean; } ``` ```typescript type Step = (page: Page, options?: Options) => void; ``` ## `dappeteer.bootstrap(options: DappeteerLaunchOptions & MetaMaskOptions): Promise<{ metaMask: Dappeteer; browser: DappeteerBrowser; metaMaskPage: DappeteerPage; }>` ```typescript type DappeteerLaunchOptions = { metaMaskVersion?: | "latest" | "local" | string; metaMaskLocation?: Path; metaMaskPath?: string; metaMaskFlask?: boolean; automation?: "puppeteer" | "playwright"; puppeteerOptions?: Omit[0], "headless">; playwrightOptions?: Omit; userDataDir?: string; key?: string; }; type MetaMaskOptions = { seed?: string; password?: string; showTestNets?: boolean; }; ``` it runs `dappeteer.launch` and `dappeteer.setupMetaMask` and returns an object with metaMask, metaMaskPage and browser. ## `dappeteer.initSnapEnv( opts: DappeteerLaunchOptions & MetaMaskOptions & InstallSnapOptions & { snapIdOrLocation: string }): Promise<{ metaMask: Dappeteer; browser: DappeteerBrowser; metaMaskPage: DappeteerPage; snapId: string;}` ```typescript type DappeteerLaunchOptions = { metaMaskVersion?: | "latest" | "local" | string; metaMaskLocation?: Path; metaMaskPath?: string; metaMaskFlask?: boolean; automation?: "puppeteer" | "playwright"; browser: "chrome"; puppeteerOptions?: Omit[0], "headless">; playwrightOptions?: Omit; }; type MetaMaskOptions = { seed?: string; password?: string; showTestNets?: boolean; }; type InstallSnapOptions = { customSteps?: InstallStep[]; version?: string; installationSnapUrl?: string; } ``` it runs `dappeteer.launch` and `dappeteer.setupMetamask` and `snaps.installSnap` and returns an object with metaMask, metaMaskPage, browser and snapId. ## `dappeteer.getMetaMaskWindow(browser: Browser, version?: string): Promise` # MetaMask methods `metaMask` is used as placeholder for dAppeteer returned by [`setupMetaMask`](setup) or [`getMetaMaskWindow`](getMetaMask) ## `metaMask.switchAccount(accountNumber: number): Promise` it commands MetaMask to switch to a different account, by passing the index/position of the account in the accounts list. ## `metaMask.importPK(privateKey: string): Promise` it commands MetaMask to import a private key. It can only be used while you haven't signed in yet, otherwise it throws. ## `metaMask.lock(): Promise` signs out from MetaMask. It can only be used if you already signed it, otherwise it throws. ## `metaMask.unlock(password: string): Promise` it unlocks the MetaMask extension. It can only be used in you locked/signed out before, otherwise it throws. The password is optional, it defaults to `password1234`. ## `metaMask.switchNetwork(network: string): Promise` it changes the current selected network. `networkName` can take the following values: `"mainnet"`, `"goerli"`, `"sepolia"`, `"ropsten"`, `"rinkeby"`, `"kovan"`, `"localhost"`. ## `metaMask.acceptAddNetwork(shouldSwitch?: boolean): Promise` commands MetaMask to accept a Network addition. For this to work MetaMask has to be in a Network addition state (basically prompting the user to accept/reject a Network addition). You can optionally tell MetaMask to switch to this network by passing the `true` parameter (default to `false`). ## `metaMask.rejectAddNetwork(): Promise` commands MetaMask to reject a Network addition. For this to work MetaMask has to be in a Network addition state (basically prompting the user to accept/reject a Network addition). ## `metaMask.acceptAddToken(): Promise` commands MetaMask to accept a Token addition. For this to work MetaMask has to be in a Token addition state (basically prompting the user to accept/reject a Token addition). ## `metaMask.rejectAddToken(): Promise` commands MetaMask to reject a Token addition. For this to work MetaMask has to be in a Token addition state (basically prompting the user to accept/reject a Token addition). ## `metaMask.confirmTransaction(options?: TransactionOptions): Promise` ```typescript interface TransactionOptions { gas?: number; gasLimit?: number; priority?: number; } ``` commands MetaMask to submit a transaction. For this to work MetaMask has to be in a transaction confirmation state (basically prompting the user to submit/reject a transaction). You can (optionally) pass an object with `gas` and/or `gasLimit`, by default they are `20` and `50000` respectively. ## `metaMask.sign(): Promise` commands MetaMask to sign a message. For this to work MetaMask must be in a sign confirmation state. ## `metaMask.signTypedData(): Promise` commands MetaMask to sign a message. For this to work MetaMask must be in a sign typed data confirmation state. ## `metaMask.approve(): Promise` enables the app to connect to MetaMask account in privacy mode # Helpers methods ## `metaMask.helpers.getTokenBalance(tokenSymbol: string): Promise` get balance of specific token ## `metaMask.helpers.deleteAccount(accountNumber: number): Promise` deletes account containing name with specified number ## `metaMask.helpers.deleteNetwork(): Promise` deletes custom network from metaMask ## `metaMask.page` is the MetaMask plugin `Page` **for advanced usages** in case you need custom features. # Snaps methods ## `metaMask.snaps.installSnap: (snapIdOrLocation: string, opts?: { customSteps?: InstallStep[]; version?: string;},installationSnapUrl?: string`) => Promise; installs the snap. The `snapIdOrLocation` param is either the snapId or the full path to your snap directory. ## `metaMask.snaps.invokeSnap(page: DappeteerPage,snapId: string,method: string,params?: Params): Promise>` invokes a MetaMask snap method. The snapId is the id of your installed snap (result of invoking `installSnap` method). This function will throw if there is an error while invoking snap. ## `metaMask.snaps.getNotificationEmitter(): Promise` returns emitter to listen for notifications appearance in notification page ## `metaMask.snaps.getAllNotifications(): Promise` Returns all notifications in MetaMask notifications page ## `metaMask.snaps.dialog.accept(): Promise` accepts a snap_dialog dialog ## `metaMask.snaps.dialog.reject(): Promise` rejects snap_dialog dialog ## `metaMask.snaps.dialog.type(value: string): Promise` type value in snap_dialog dialog