npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eth-lawyer

v2.0.3

Published

Detect Metamask login, logout & Conveniently interact with Ethereum Smart Contracts.

Readme

https://github.com/QuantumProductions/eth-lawyer

Detect Metamask login, logout & Conveniently interact with Ethereum Smart Contracts.

Most Smart Contract web apps require detection of Metamask accounts.

EthLawyer handles the boilerplate of detecting:

  • Metamask not installed
  • Metamask installed but locked
  • Metamask installed & unlocked
var callback = function(event, data) {
  if (event == 'eth-lawyer-account') {
    //data.address
    //data.hasMetamask
  }
}

//EthLawyer will fire its callback just upon the Metamask account changing by default.
//pass in spam: true to its params to get notified every 5 seconds of the current Metamask account.
window.lawyer = new EthLawyer({spam: true, callback: callback});

//Create a lawyer to interact with a smart contract.
window.lawyer = new EthLawyer({address: "0x..", "abi": "...", spam: false, callback: callback});

The EthLawyer's Smart Contract can be accessed directly with

lawyer.contract

or you can call and get a Promise with:

lawyer.filePaperworkWei(functionName, functionParams, wei, gasPrice)
//wei is optional
//gasPrice is optional
//returns a Promise, with success being the transaction hash.

I recommend you read the index.js here. This is a simple module and it's good to know what it's doing under the hood.

Currently Metamask supports Ethereum 0.2X API. Make note of which documentation you're reading on the Web3 Github page as there are differences.

For a more complete example, check out the example folder which demonstrates displaying user Account address + balance in react, updating when a new account is switched to or Metamask is locked/unlocked.

This React example also showcases lawyer.canAfford(eth), to determine if the current account has a minimum of eth balance. The conversion from Eth to Wei is handled by the lawyer, or you can call lawyer.canAffordWei(weiAsBigNumber) using bignumber.js

The React example hides & shows a button based on the lawyer.canAfford result for 0.001 Ethereum.

I hope this saves you time.

const EthLawyer = require('eth-lawyer');
var callback = function(event, data) {
  if (event == 'eth-lawyer-account') {
    //also included: data.hasMetamask -- false if no web3 detected
    if (data.address) { //data.address null if locked
      let promise = data.lawyer.canAfford(5); //in eth. to use wei, convert wei to BigNumber and call .canAffordWei
      promise.then(function(result) {
        console.log(result); //can afford, show to user
        //TODO: show prompt for buy
      }, function(error) {
        console.log("Insufficient" + error);
      });
    }
  }
}
  

//Create EthLawyer just to read account balances.
//spam: true will announce current account status every 5 seconds
//spam: false will only announce when the Metamask address changes (including null)
window.lawyer = new EthLawyer({spam: true, callback: callback});

//Create a lawyer to interact with a smart contract.
window.lawyer = new EthLawyer({address: "0x..", "abi": "...", spam: false, callback: callback});

//Dev Donation: 0x2c3b0F6E40d61FEb9dEF9DEb1811ea66485B83E7