sai-soum / providers

An Ethereum Provider that connects over a stream, as injected into websites by MetaMask

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MetaMask Providers

The Ethereum provider object injected by MetaMask into various environments. Contains a lot of implementation details specific to MetaMask, and is probably not suitable for out-of-the-box use with other wallets.

The BaseProvider implements the Ethereum JavaScript provider specification, EIP-1193. MetamaskInpageProvider implements EIP-1193 and legacy interfaces.

Installation

yarn add @metamask/providers

Usage

import { initializeProvider } from '@metamask/providers';

// Create a stream to a remote provider:
const metamaskStream = new LocalMessageDuplexStream({
  name: 'inpage',
  target: 'contentscript',
});

// this will initialize the provider and set it as window.ethereum
initializeProvider({
  connectionStream: metamaskStream,
});

const { ethereum } = window;

Types

Types are exposed at index.d.ts. They require Node.js EventEmitter and Duplex stream types, which you can grab from e.g. @types/node.

Do Not Modify the Provider

The Provider object should not be mutated by consumers under any circumstances. The maintainers of this package will neither fix nor take responsbility for bugs caused by third parties mutating the provider object.

Running tests

yarn test

About

An Ethereum Provider that connects over a stream, as injected into websites by MetaMask

License:MIT License


Languages

Language:TypeScript 98.7%Language:JavaScript 1.3%