# 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:

```javascript

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**](https://docs.metamask.io/snaps/reference/rpc-api/#wallet_requestsnaps).

### **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:**

```javascript
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:**

```javascript
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,
            },
          },
        ],
        }
      },
    },
  },
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.leapwallet.io/cosmos/leap-metamask-snap/integrating-snaps/metamask-cosmos-snap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
