Skip to content

D3Portillo/usemetamask

Repository files navigation

useMetamask 🦍

An utility React hook to handle Metamask's browser API

Installation

npm i @forta/usemetamask

Getting 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 */
})

READ THE DOCS 🌟 | FOLLOW ME 🐦