Options
All
  • Public
  • Public/Protected
  • All
Menu

Package @purser/metamask

@purser/metamask

A javascript library to interact with the a Metamask based Ethereum wallet. It extracts all the complexity from setting up, maintaining and interacting with it, while providing you with a predictable interface.

Installation

npm install ethers @purser/metamask

Quick Usage

import { open } from '@purser/metamask'

const wallet = await open();

console.log(wallet); // { address: '...', chainId: '...', publicKey: '...' }

Documentation

You can find more in-depth description for this module's API in the purser docs.

Contributing

This package is part of the purser monorepo package.

Please read our Contributing Guidelines for how to get started.

License

The @purser/metamask library along with the whole purser monorepo are MIT licensed.

Index

Classes

Interfaces

Variables

Functions

Variables

Const messages

messages: { cancelMessageSign: string; cancelTransactionSign: string; cannotAddHook: string; cannotSendTransaction: string; cannotSignMessage: string; didNotAuthorize: string; dontSetNonce: string; legacyMode: string; metamaskNotAvailable: string; signMessageArgumentMissing: string } = staticMethods

Type declaration

  • cancelMessageSign: string
  • cancelTransactionSign: string
  • cannotAddHook: string
  • cannotSendTransaction: string
  • cannotSignMessage: string
  • didNotAuthorize: string
  • dontSetNonce: string
  • legacyMode: string
  • metamaskNotAvailable: string
  • signMessageArgumentMissing: string

Functions

Const accountChangeHook

  • accountChangeHook(callback: AccountsChangedCallback): Promise<void>
  • Hook into Metamask's state events observers array to be able to act on account changes from the UI

    It's a wrapper around the setStateEventObserver() helper method

    Parameters

    • callback: AccountsChangedCallback

      Function to add the state events update array It receives the state object as an only argument

    Returns Promise<void>

    Does not return noting

Const detect

  • detect(): Promise<boolean>
  • Check if Metamask's injected web3 proxy instance is available in the global object.

    Makes use of the detect() helper, basically it's a wrapper that exposes it from the module.

    Returns Promise<boolean>

    Only returns true if it's available, otherwise it will throw.

Const open

  • open(): Promise<MetaMaskWallet>
  • Open the Metamask Wallet instance

    Returns Promise<MetaMaskWallet>

    The wallet object resulted by instantiating the class (Object is wrapped in a promise).

Generated using TypeDoc