An utility React hook to handle Metamask's browser API
npm i @forta/usemetamask
import { useMetamask } from "@forta/usemetamask"
function App() {
const { account, connect, balance } = useMetamask()
return (
<div>
<p>Address: {account}</p>
<p>BALANCE: {balance}ETH</p>
<button onClick={connect}>CONNECT</button>
</div>
)
}
import { parse, useMetamask } from "@forta/usemetamask"
// ..
const { send } = useMetamask()
send({
to: "0x3c0e20fCA6d2E084127D056377a5f35294503447",
value: parse.toTxWei(0.5),
/* 0.5 in ETH. Request expects wei in HEX value.
.toTxWei parses a number to wei & then to HEX */
})