neeboo / schnorr_snap

A schnorr plugin for metamask snap, nostr supported
6 stars 1 forks source link

Update Metamask integration to use the correct Snaps JSON-RPC API methods #1

Open bluabaleno opened 1 year ago

bluabaleno commented 1 year ago

While trying to integrate the Schnorr Snap with Metamask, I encountered an issue with the metamask.ts file in the example package. The code was using the wallet_enable method, which is not part of the Snaps JSON-RPC API documentation.

After reviewing the Snaps JSON-RPC API documentation, I found that the correct method to use is wallet_requestSnaps. I updated the metamask.ts file accordingly, and the integration started working as expected.

Here's the updated code snippet for reference:

import { ethereum } from "@metamask/providers";

async function initiateSchnorrSnap(network: SchnorrNetwork = "local"): Promise<SnapInitializationResponse> {
  const snapId = process.env.SNAP_ID;

  try {
    console.log("Attempting to connect to snap...");

    const result = await ethereum.request({
      method: 'wallet_requestSnaps',
      params: {
        [snapId]: {
          version: "latest",
        },
      },
    });

    const metamaskSchnorrSnap = new MetamaskSchnorrSnap(snapId, network);
    isInstalled = true;
    console.log("Snap installed!");
    return { isSnapInstalled: true, snap: metamaskSchnorrSnap };
  } catch (e) {
    console.error(e);
    isInstalled = false;
    return { isSnapInstalled: false };
  }
}

I recommend updating the example code to use the correct Snaps JSON-RPC API methods, so that others don't encounter the same issue during the integration process.

neeboo commented 1 year ago

Hey, snap JSON API updates recently, I will update it ASAP. Thanks

neeboo commented 1 year ago

I have a new snap repo which combine ordinals and nostr related libraries.

you can check it here: https://github.com/AstroxNetwork/ord_snap