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(){
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 {
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xA86A' }],
params: [{ chainId: chainId }],
});
} catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask.
@ -20,15 +36,15 @@ async function confirmAvalanche(){
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0xA86A',
chainName: 'Avalanche',
chainId: chainId,
chainName: name,
nativeCurrency: {
name: 'Avalanche',
symbol: 'AVAX',
decimals: 18,
},
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
blockExplorerUrls: ['https://snowtrace.io'],
rpcUrls: [rpcUrl],
blockExplorerUrls: [explorerUrl],
}],
});
} catch (addError) {

Loading…
Cancel
Save