Monarch White-Label API Overview
  • ⚙️Monarch API Calls
    • Creating an Invoice
      • POST
      • RETURNS
    • Generating Payment Data
      • POST
      • RETURNS
    • Check Allowance
      • POST
      • RETURNS
    • Generate Approve Transaction
  • 💸WalletConnect
  • 🦊MetaMask
  • 📮POSTing a Payment
Powered by GitBook
On this page

MetaMask

PreviousWalletConnectNextPOSTing a Payment

Last updated 1 year ago

The MetaMask API is attached to the window object if MetaMask is installed.

if (!window.ethereum) throw new Error("Meta Mask is not installed!");

/# You must first request access to the users MetaMask Only do this once #/
try {
  const accounts = await window.ethereum.request({ method: "eth_requestAccounts" })
} catch(error) {
  if (error.code === 4001) {
     // EIP-1193 userRejectedRequest error
     console.log("Please connect to MetaMask.");
   } else {
     console.error(error);
   }
  return;
}

const [from] = await window.ethereum.request({
   		 method: "eth_accounts",
   	 });

const tx = {
  to: "0x"
  from,
  gas: "300000",
  data: "0x"
}
window.ethereum.request({
   	 method: "eth_sendTransaction",
   	 params: [tx],
    });
🦊
https://docs.metamask.io/wallet/reference/rpc-api/
JSON-RPC API | MetaMask developer documentation
Logo