Skip to content

Latest commit

 

History

History
160 lines (132 loc) · 5.17 KB

API.md

File metadata and controls

160 lines (132 loc) · 5.17 KB

dAppeteer API

Methods provided by dAppeteer.
For additional information read root readme

dAppeteer setup methods

dappeteer.launch(puppeteerLib: typeof puppeteer, options: OfficialOptions | CustomOptions): Promise<Browser>

interface OfficialOptions {
  metamaskVersion: 'latest' | string;
  metamaskLocation?: Path;
};

type Path = string | { download: string; extract: string; };

or

interface CustomOptions {
  metamaskPath: string;
};

returns an instance of browser same as puppeteer.launch, but it also installs the MetaMask extension. It supports all the regular puppeteer.launch options

dappeteer.setupMetamask(browser: Browser, options: MetamaskOptions = {}, steps: Step[]): Promise<Dappeteer>

interface MetamaskOptions {
  seed?: string;
  password?: string;
  showTestNets?: boolean;
}
type Step = (page: Page, options?: Options) => void;

dappeteer.bootstrap(puppeteerLib: typeof puppeteer, options: OfficialOptions & MetamaskOptions): Promise<[Dappeteer, Page, Browser]>

interface OfficialOptions {
  metamaskVersion: 'latest' | string;
  metamaskLocation?: Path;
};

it runs dappeteer.launch and dappeteer.setup and return array with dappetter, page and browser

dappeteer.getMetamaskWindow(browser: Browser, version?: string): Promise<Dappeteer>

dAppeteer methods

metamask is used as placeholder for dAppeteer returned by setupMetamask or getMetamaskWindow

metamask.switchAccount(accountNumber: number): Promise<void>

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<void>

it commands MetaMask to import an private key. It can only be used while you haven't signed in yet, otherwise it throws.

metamask.lock(): Promise<void>

signs out from MetaMask. It can only be used if you arelady signed it, otherwise it throws.

metamask.unlock(password: string): Promise<void>

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<void>

it changes the current selected network. networkName can take the following values: "main", "ropsten", "rinkeby", "kovan", "localhost".

metamask.addNetwork(options: AddNetwork): Promise<void>

interface AddNetwork {
  networkName: string;
  rpc: string;
  chainId: number;
  symbol: string;
}

it adds a custom network to MetaMask.

metamask.addToken(tokenAddress: string): Promise<void>

interface AddToken {
  tokenAddress: string;
  symbol?: string;
  decimals?: number;
}

it adds a custom token to MetaMask.

metamask.confirmTransaction(options?: TransactionOptions): Promise<void>

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 promting 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<void>

commands MetaMask to sign a message. For this to work MetaMask must be in a sign confirmation state.

metamask.approve(): Promise<void>

enables the app to connect to MetaMask account in privacy mode

metamask.helpers

metamask.helpers.getTokenBalance(tokenSymbol: string): Promise<number>

get balance of specific token

metamask.helpers.deleteAccount(accountNumber: number): Promise<void>

deletes account containing name with specified number

metamask.helpers.deleteNetwork(): Promise<void>

deletes custom network from metamask

metamask.page is Metamask plugin Page

for advanced usages in case you need custom features.