Metamask Cosmos Snap

Installation

To either establish a connection or initiate an installation followed by a connection to the metamask-cosmos-snap, execute the following code:


try {
  const result = await window.ethereum.request({
    method: 'wallet_requestSnaps',
    params: {
      'npm:@leapwallet/metamask-cosmos-snap': {},
    },
  });

  console.log(result);

} catch (error) {
  console.log(error);
}

For the official docs on connecting or installing a Metamask snap, refer here.

Methods

1. Get Keys

The getKey method retrieves the wallet's public address corresponding to a specific chain ID. Currently, we support chains of coin type 118.

Usage:

const accountData = await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: "npm:@leapwallet/metamask-cosmos-snap",
    request: {
      method: 'getKey',
      params: {
        chainId,
      },
    },
  },
});

2. Sign Direct

Utilize the signDirect method to sign transactions or signDoc using the connected wallet.

Usage:

await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: "npm:@leapwallet/metamask-cosmos-snap",
    request: {
      method: 'signDirect',
      params: {
        chainId,
        signerAddress,
        signDoc,
      },
    },
  },
});

3. Suggest Chain

Utilize the suggestChain method to suggest any chains of coin types 118,

Usage:

await window.ethereum.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'local:http://localhost:8000',
    request: {
      method: 'suggestChain',
      params: {
        chainInfo: {
          chainId: 'coreum-mainnet-1',
          chainName: 'coreum',
          bech32Config: {
            bech32PrefixAccAddr: 'core',
          },
          bip44: {
            coinType: 990,
          },
          feeCurrencies: [
          {
            coinDenom: "ucore",
            coinMinimalDenom: "ucore",
            coinDecimals: 6,
            coinGeckoId: "coreum",
            gasPriceStep: {
              low: 0.0625,
              average: 0.5,
              high: 62.5,
            },
          },
        ],
        }
      },
    },
  },
});

Last updated