Giter Site home page Giter Site logo

node-metamask's Introduction

node-metamask

Connect Node.js to MetaMask.

"Why would I ever want to do that?" - Sometimes you might have scripts or libraries that run in Node and require signed transactions that you would like to use MetaMask for (instead of dealing with private keys). This tool functions as a web3 provider that can be used with pretty much any MetaMask instance remotely. Please, only use this package locally to prevent PITM attacks (if you're brave enough to try it on mainnet).

Sounds crazy? It probably is. Also highly experimental. Please use with caution.

Install

yarn add node-metamask

Usage

const MetaMaskConnector = require('node-metamask');
const connector = new MetaMaskConnector({
  port: 3333, // this is the default port
  onConnect() { console.log('MetaMask client connected') }, // Function to run when MetaMask is connected (optional)
});

connector.start().then(() => {
  // Now go to http://localhost:3333 in your MetaMask enabled web browser.
  const web3 = new Web3(connector.getProvider());
  // Use web3 as you would normally do. Sign transactions in the browser.
});

When you're done with your MetaMask business, run the following code to clean up:

connector.stop();

Disclaimer

As I said, this is highly experimental. Tested only with web3 v1.0 (in node) and web3 0.20.3 (MetaMask, in the browser). Also it might not work with all functions supported by web3.

Contribute

Please report any bugs you find so we can improve this.

node-metamask's People

Contributors

frods avatar hems avatar monokh avatar ryanchristo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-metamask's Issues

Metamask crashes after the connector starts

I'm trying to authenticate transactions using metamask. I execute the following code but once I connect to page localhost:3333, MetaMask plugin crashes. It tries to show me the transaction notification but then goes blank.

async function connectToMetamask() {
  const connector = new MetaMaskConnector({
    port: 3333,
    onConnect() {
      console.log('MetaMask client connected')
    },
  });

  // Now go to http://localhost:3333 in your MetaMask enabled web browser.
  console.log("Go to http://localhost:3333");
  await connector.start();
  const web3 = new Web3(connector.getProvider());
  // Use web3 as you would normally do. Sign transactions in the browser.
  CampaignContract.setProvider(connector.getProvider());
}

Screenshot from 2020-06-19 12-10-59

Use with ColonyNetworkClient

Hello, I'm trying to use this with ColonyNetworkClient to create a colony on the rinkeby network with my MetaMask.

You can see what I have so far here: https://github.com/Pioneercoinio/PioneerColony/blob/MetaMaskClient/src/metamask_client.js

It seems that the contracts are not being loaded from rinkeby. The error I get is

(node:85249) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
    at _callee$ (/github/pioneercoinio/PioneerColony/src/pioneercolony.js:7:40)

Any idea on what I'm missing?

Errors using package with the latest version of web3

Description

node-metamask currently does not support the latest beta release of the web3 package. I received the following error running node-metamask with web3 version 1.0.0-beta.51:

Error: method.split is not a function

I was able to successfully run node-metamask with web3 version 1.0.0-beta.35. I have not yet tried to run it with any other versions between beta.35 and beta.51.

"start" promise never resolved?

I'm running the latest version of MetaMask on my GoogleChrome on OSX and when i run the javascript example on my node ( version 9 ), the "start" promise is never resolved.

It just hangs in there and no callbacks are ever called.

What i'm a doing wrong? ( I'm running exactly the readme file example )

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.