
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
eth-lawyer
Advanced tools
Detect Metamask login, logout & Conveniently interact with Ethereum Smart Contracts.
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:
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
FAQs
Detect Metamask login, logout & Conveniently interact with Ethereum Smart Contracts.
We found that eth-lawyer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.