Api to add Harmony chain to Metamask
This api provide developers & users simple add / switch Harmony chain to Metamask wallet
Developers can use this sources to provide users easy configure or switch to correct Harmony chain and shard. (by analogy with https://chainlist.org/)
1
const chainId = 2; // 0-3 - harmony chain
2
3
window.web3.eth.getAccounts((e, t) => {
4
window.ethereum.request({
5
method: 'wallet_addEthereumChain',
6
params: [
7
{
8
chainId: '0x' + Number(1666600000 + chainId).toString(16),
9
chainName: Harmony Mainnet Shard ${chainId},
10
nativeCurrency: { name: 'ONE', symbol: 'ONE', decimals: 18 },
11
rpcUrls: [https://s${chainId}.api.harmony.one],
12
blockExplorerUrls: ['https://www.harmony.one/'],
13
},
14
t[0],
15
],
16
});
17
});
Copied!
After call this method - user will see message to approve adding or switching to correct Harmony chain.
You can see more information about this api here https://docs.metamask.io/guide/rpc-api.html#wallet-addethereumchain
Last modified 4mo ago
Export as PDF
Copy link