See eip-3085 and metamask method
For security use chains.json (https://chainid.network/)
const chain = {
chainId: "0x38",
chainName: "Binance Smart Chain Mainnet",
nativeCurrency: {
name: "Binance Chain Native Token",
symbol: "BNB",
decimals: 18,
},
rpcUrls: [
"https://bsc-dataseed1.binance.org",
"https://bsc-dataseed2.binance.org",
"https://bsc-dataseed3.binance.org",
"https://bsc-dataseed4.binance.org",
"https://bsc-dataseed1.defibit.io",
"https://bsc-dataseed2.defibit.io",
"https://bsc-dataseed3.defibit.io",
"https://bsc-dataseed4.defibit.io",
"https://bsc-dataseed1.ninicoin.io",
"https://bsc-dataseed2.ninicoin.io",
"https://bsc-dataseed3.ninicoin.io",
"https://bsc-dataseed4.ninicoin.io",
"wss://bsc-ws-node.nariox.org",
],
blockExplorerUrls: ["https://www.bscscan.com/"],
iconUrls: [
"https://bin.bnbstatic.com/image/admin_mgs_image_upload/20201110/550eda20-1b9a-4bc7-9a65-e4a329e8bb57.png",
],
};
window.ethereum
.request({
method: "wallet_addEthereumChain",
params: [chain],
})
.catch((error) => {
console.log(error);
alert(
"An error has occurred. Please make sure the metamask is ready to go. See error in log"
);
});