Coder Social home page Coder Social logo

whaletogether / extension-provider Goto Github PK

View Code? Open in Web Editor NEW

This project forked from metamask/extension-provider

0.0 0.0 0.0 312 KB

A module for allowing a WebExtension to access the web3 provider from an installed MetaMask instance

License: MIT License

JavaScript 99.98% HTML 0.02%

extension-provider's Introduction

MetaMask Extension Provider

A module for providing a MetaMask provider to other WebExtensions.

The account provided by this provider will be the user's MetaMask account.

When sending signing requests to this provider, MetaMask will prompt the user to sign with their accounts.

Works in:

  • Chrome
  • Firefox

Installation

Using npm as a package manager:

npm install metamask-extension-provider -S

Usage

Using a bundler like browserify:

const createMetaMaskProvider = require('metamask-extension-provider')

const provider = createMetaMaskProvider()

provider.on('error', (error) => {
  // Failed to connect to MetaMask, fallback logic.
})

// Enjoy!

Adding additional browser support

Simply add MetaMask's extension ID for that browser's store to the config file.

Running the example

Use the ./sample-extension folder as an WebExtension. You can easily add it to Chrome or Firefox Developer Edition.

Editing the example

You must have browserify installed (npm i -g browserify).

You can edit the sample file sample-extension/index.js and then rebuild the file with npm run buildSample.

Using with a local Development copy of MetaMask

You'll need to edit the method getMetaMaskId() to return your local development MetaMask's id. You can get that from your MetaMask console with chrome.runtime.id.

Current Limitations

In order to identify when there is a problem (like MetaMask was not connected), some kind of proper error handling must be added to metamask-inpage-provider that exposes the errors to the consumer of the provider. Maybe making it an event-emitter, so it can emit its errors, instead of just logging them.

extension-provider's People

Contributors

danfinlay avatar dependabot[bot] avatar guanbinrui avatar jack-works avatar powersource avatar whymarrh avatar zhouhanseng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.