Add or Switch to Harmony chain on Metamask
This tutorial help developers to interact with Metamask installed on a user's device, to add (or switch to) the Harmony chain's network.
// 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);
}
Last updated
Was this helpful?