Skip to content

Instantly share code, notes, and snippets.

@mainnet-pat
Last active October 26, 2021 06:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mainnet-pat/f70885d9f0c828248dbdfea659274dda to your computer and use it in GitHub Desktop.
Save mainnet-pat/f70885d9f0c828248dbdfea659274dda to your computer and use it in GitHub Desktop.
Add SmartBch to Metamask
// paste this in your browser's console window (ctrl + alt + I)
try {
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x2710' }],
});
} catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902) {
try {
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0x2710',
chainName: 'SmartBch Mainnet',
blockExplorerUrls: ['https://www.smartscan.cash/'],
rpcUrls: ["https://smartbch.fountainhead.cash/mainnet:8545", "https://smartbch.greyh.at:8545", "https://rpc.uatvo.com:8545"],
nativeCurrency: {
name: 'BCH',
symbol: 'BCH',
decimals: 18,
},
}],
});
} catch (addError) {
// handle "add" error
}
}
// handle other "switch" errors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment