Metamask Checker — Core
Description
Core part of the react-metamask-checker and vue-metamask-checker components.
Note: only new version of Metamask API is supported. Related links:
- https://medium.com/metamask/breaking-changes-to-the-metamask-inpage-provider-b4dde069dd0a
- https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#new-api
Installation
yarn add @metamask-checker/core
# or
npm install --save @metamask-checker/core
Testing
yarn test:jest # Runs Jest with coverage collection
yarn test:coverage # Sends coverage to .coveralls.io
yarn test # yarn test:jest && yarn test:coverage
# or
npm run test:jest
npm run test:coverage
npm test
Usage
import checkMetamask from '@metamask-checker/core'
(async () => {
try {
const { selectedNetwork, selectedAccount } = await checkMetamask(
window.ethereum,
// networkId or chainId decimal number value,
// account address string value,
)
// ...code
} catch (error) {
console.error(error)
}
})()