> For the complete documentation index, see [llms.txt](https://docs.harmony.one/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.harmony.one/home/developers/wallets/metamask/add-or-switch-to-harmony-chain-on-metamask.md).

# Add or Switch to Harmony chain on Metamask

Harmony is a multi-sharded chain, currently with shard 0, 1, 2 and 3 running on Mainnet.  To execute the code snippet below successfull, you can test on a device that has Metamask extension / add-on installed and visible to your app.

```javascript
// Harmony's Shard ID {0..3}
const shardId = 0;

try {
  const walletAddEthereumChainRequest = await ethereum.request({
    method: 'wallet_addEthereumChain',
    params: [
      {
        chainId: '0x' + Number(1666600000 + shardId).toString(16),
        chainName: 'Harmony Mainnet Shard ' + shardId,
        nativeCurrency: { name: 'ONE', symbol: 'ONE', decimals: 18 },
        rpcUrls: ['https://' + (shardId === 0 ? 'api.harmony.one' : 'api.s' + shardId + '.t.hmny.io')],
        blockExplorerUrls: ['https://explorer.harmony.one/'],
      },
    ],
  });
} catch (error) {
  console.error(error);
}
```

{% hint style="info" %}
Please note that `window.web3` has been [deprecated](https://docs.metamask.io/guide/provider-migration.html#summary-of-breaking-changes).  Use `window.ethereum` instead.  To migrate, use [this guide from Metamask](https://docs.metamask.io/guide/provider-migration.html#table-of-contents).
{% endhint %}

When this code snippet is executed, users will see message to approve adding or switching to correct Harmony chain.

![Metamask pops up asking to Switch Network to Harmony Mainnet Shard 0](/files/EuCoOUJpy1SOXoDuPgfF)

You can see more information about Metamask documentation related to the Ethereum Provider API at <https://docs.metamask.io/guide/ethereum-provider.html>

To see a full list of Chain IDs, please visit <https://chainlist.org/> and search for `Harmony`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.harmony.one/home/developers/wallets/metamask/add-or-switch-to-harmony-chain-on-metamask.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
