@forta/usemetamask
v0.2.0
Published
Utility React hook to handle Metamask's browser API
Downloads
42
Maintainers
Readme
useMetamask 🦍
Install
npm i @forta/usemetamask
Get Started
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>
)
}
Send Ether
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 */
})