Skip to content

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

License

Notifications You must be signed in to change notification settings

copperexchange/inpage-provider

 
 

Repository files navigation

MetaMask Inpage Provider

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

Implements the Ethereum JavaScript provider specification, EIP-1193.

Installation

yarn add @metamask/inpage-provider

Usage

import { initializeProvider } from '@metamask/inpage-provider'

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 60.5%
  • JavaScript 39.1%
  • Shell 0.4%