Answers for "Automatic wallet connect"

0

Automatic wallet connect

async function addPolygonTestnetNetwork(){
    try {
        await ethereum.request({
            method: 'wallet_switchEthereumChain',
            params: [{ chainId: '0x13881' }], // Hexadecimal version of 80001, prefixed with 0x
        });
    } catch (error) {
        if (error.code === 4902) {
            try {
                await ethereum.request({
                    method: 'wallet_addEthereumChain',
                    params: [{ 
                        chainId: '0x13881', // Hexadecimal version of 80001, prefixed with 0x
                        chainName: "POLYGON Mumbai",
                        nativeCurrency: {
                            name: "MATIC",
                            symbol: "MATIC",
                            decimals: 18,
                        },
                        rpcUrls: ["https://speedy-nodes-nyc.moralis.io/cebf590f4bcd4f12d78ee1d4/polygon/mumbai"],
                        blockExplorerUrls: ["https://explorer-mumbai.maticvigil.com/"],
                        iconUrls: [""],
                
                    }],
                });
            } catch (addError){
                console.log('Did not add network');
            }
        }
    }
}
Posted by: Guest on February-06-2022

Browse Popular Code Answers by Language