setup network switchers and checks

main
lza_menace 3 years ago
parent 2c2782797a
commit 5b7641d16d

@ -8,10 +8,26 @@ async function getSignedData(publicAddress, jsonData) {
} }
async function confirmAvalanche(){ async function confirmAvalanche(){
let debug = true;
let chainId;
let rpcUrl;
let explorerUrl;
let name;
if (debug) {
name = 'Avalance Testnet';
chainId = '0xA869';
rpcUrl = 'https://api.avax-test.network/ext/bc/C/rpc';
explorerUrl = 'https://testnet.snowtrace.io';
} else {
name = 'Avalanche Mainnet';
chainId = '0xA86A';
rpcUrl = 'https://api.avax.network/ext/bc/C/rpc';
explorerUrl = 'https://snowtrace.io';
}
try { try {
await ethereum.request({ await ethereum.request({
method: 'wallet_switchEthereumChain', method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xA86A' }], params: [{ chainId: chainId }],
}); });
} catch (switchError) { } catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask. // This error code indicates that the chain has not been added to MetaMask.
@ -20,15 +36,15 @@ async function confirmAvalanche(){
await ethereum.request({ await ethereum.request({
method: 'wallet_addEthereumChain', method: 'wallet_addEthereumChain',
params: [{ params: [{
chainId: '0xA86A', chainId: chainId,
chainName: 'Avalanche', chainName: name,
nativeCurrency: { nativeCurrency: {
name: 'Avalanche', name: 'Avalanche',
symbol: 'AVAX', symbol: 'AVAX',
decimals: 18, decimals: 18,
}, },
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'], rpcUrls: [rpcUrl],
blockExplorerUrls: ['https://snowtrace.io'], blockExplorerUrls: [explorerUrl],
}], }],
}); });
} catch (addError) { } catch (addError) {

Loading…
Cancel
Save