PageSourceSearch

https://polygonscan.com/assets/js/custom/wallet-handling-connect.js?v=26.9.3.0

js polygonscan.com collected 2026-09-24 08:28:32 UTC 26,283 bytes, 809 lines download raw bytes

1//wallet connect
2//var WalletConnectProvider = window["@walletconnect/ethereum-provider"].EthereumProvider;
3const WalletConnectProjectId = "c441e32d31db9533e084675f7290897d";
4const WalletConnectInfuraId = "7809098bc3af4ebdb57464bffac0242c";
5const bridgeUrl = "https://etherscan.bridge.walletconnect.org";
6const WalletConnect_Url = "https://walletconnect.com/";
7const WalletConnect_Icon = "https://avatars.githubusercontent.com/u/37784886";
8
9
10//wallet link
11const WalletLinkInfuraId = "e3301c1a14f943c0b2f3801cb6c7e347";
12const WalletLink = window.WalletLink;
13// Chosen wallet provider given by the dialog window
14let provider; //required
15
16
17let web3Modal; 
18
19let providers = [];
20
21
22function ListenProviderList() {
23    window.addEventListener(
24        "eip6963:announceProvider",
25        function (event) {
26            providers.push(event.detail);
27        }
28    );
29
30    window.dispatchEvent(new Event("eip6963:requestProvider"));
31}
32
33async function initweb3walletProvider(providerName) {
34    console.log(providers);
35    var provider;
36    var iseip6963 = false;
37    //get selected provider from available providers
38    let SelectedProvider = providers.find((p) => p.info.name == providerName);
39
40    // if provider available then use the provider for web3 injection, else use general web3.ethereum 
41    if (typeof SelectedProvider !== 'undefined') {
42        web3obj = new Web3(SelectedProvider.provider);
43        provider = SelectedProvider.provider;
44        iseip6963 = true;
45    }
46    else {
47        const Web3Modal = window.Web3Modal.default;
48        if (typeof parent.ethereum !== 'undefined') {
49            if (parent.ethereum.providers?.length > 1) {
50                // choose not isCoinbaseWallet - CoinbaseWallet has an official WalletLink package
51                let indexProvider = parent.ethereum.providers.findIndex((provider) => provider.isCoinbaseWallet);
52                // not found coinbase provider
53                if (indexProvider < 0) {
54                    indexProvider = 0;
55                } else if (indexProvider == 0) {
56                    indexProvider = 1;
57                } else {
58                    indexProvider = indexProvider - 1;
59                }
60                web3obj = new Web3(parent.ethereum.providers[indexProvider]);
61                ethereum = parent.ethereum.providers[indexProvider];
62            } else {
63                ethereum = parent.ethereum;
64                web3obj = new Web3(parent.ethereum);
65            }
66
67        } else if (typeof ethereum !== 'undefined') {
68            web3obj = new Web3(ethereum);
69        } else if (typeof web3 !== 'undefined') {
70            web3obj = new Web3(web3.givenProvider);
71        } else {
72            web3obj = new Web3(new Web3HttpProvider('https://' + net + '.infura.io/v3/dbd67a522fc4476c95ca076ac34d69fc'));
73        }
74
75        provider = window.ethereum
76    }
77
78    return { web3obj, provider, iseip6963 };
79}
80
81async function initweb3wallet() { 
82    const Web3Modal = window.Web3Modal.default;
83    if (typeof parent.ethereum !== 'undefined') {
84        if (parent.ethereum.providers?.length > 1) {
85            // choose not isCoinbaseWallet - CoinbaseWallet has an official WalletLink package
86            let indexProvider = parent.ethereum.providers.findIndex((provider) => provider.isCoinbaseWallet);
87            // not found coinbase provider
88            if (indexProvider < 0) {
89                indexProvider = 0;
90            } else if (indexProvider == 0) {
91                indexProvider = 1;
92            } else {
93                indexProvider = indexProvider - 1;
94            }
95            web3obj = new Web3(parent.ethereum.providers[indexProvider]);
96            ethereum = parent.ethereum.providers[indexProvider];
97        } else {
98            web3obj = new Web3(parent.ethereum);
99            ethereum = parent.ethereum;
100        }
101
102    } else if (typeof ethereum !== 'undefined') {
103        web3obj = new Web3(ethereum);
104    } else if (typeof web3 !== 'undefined') {
105        web3obj = new Web3(web3.givenProvider);
106    } else {
107        web3obj = new Web3(new Web3HttpProvider('https://' + net + '.infura.io/v3/dbd67a522fc4476c95ca076ac34d69fc'));
108    }
109
110    return web3obj;
111}
112
113
114
115// Note: In future to comment or remove
116async function initConnectWallet(networkChainid, SiteNetId, SitePublicRpcUrl) {
117    const Web3Modal = window.Web3Modal.default;
118    SiteNetId.toString()
119    var WalletConnectProvider = window["@walletconnect/ethereum-provider"].EthereumProvider;
120    var walletConnectObj = await WalletConnectProvider.init({
121        projectId: WalletConnectProjectId, // REQUIRED your projectId
122        chains: [networkChainid],
123        showQrModal: true,
124        rpcMap:
125        {
126            [SiteNetId] : SitePublicRpcUrl
127        }
128    });
129    return walletConnectObj
130}
131
132// Note: In future to comment or remove
133async function connectConnectWallet(walletConnectObj) {
134    // is there a way for us to catch the qrmodal rejection and flush the object? TODO
135    try {
136        var walletConnectEnableTask = walletConnectObj.connect();
137        await walletConnectEnableTask;
138        walletConnectObj.on('disconnect', function (error, payload) {
139            window.location.reload(true)
140        });
141        setTimeout(() => {
142            $(".walletconnect-modal__footer>a").on("click", (el) => {
143                if ($(el.currentTarget).html() == "Copy to clipboard") {
144                    alert("Successfully copied to clipboard");
145                }
146            })
147        });
148
149        web3obj = new Web3(walletConnectObj);
150        return web3obj;
151
152    } catch (err) {
153        alert('Failed to establish a connection to ' + type + '.');
154        await exitProvider();
155        return;
156    }
157}
158
159async function disconnect(walletConnectObj) {
160    if (walletConnectObj) {
161        await walletConnectObj.disconnect();
162        window.location.reload(true);
163    }
164}
165
166
167async function initwalletLink(chainid, mainnetName, strExplorerUrl, strFavIcon) {
168    const CoinbaseWalletSDK = window.CoinbaseWalletSDK;
169
170    const web3Modal = new CoinbaseWalletSDK({
171        appName: mainnetName,  // Your dApp's name
172        appLogoUrl: strFavIcon,  // Optional logo URL
173        darkMode: false  // Optional: Use dark mode
174    });
175
176    return web3Modal;
177}
178
179async function connectWalletLink(type, web3Modal, chainid, acceptedChainId) {
180    provider = web3Modal.makeWeb3Provider(window.ethereum, chainid);
181
182    web3obj = new Web3(provider);
183    await provider.request({ method: 'eth_requestAccounts' })
184
185    /* To catter smart wallet change chainid, 
186   as from browser plugin select using smart wallet
187   will not change accordingly default chain mainnet */
188    network = await web3obj.eth.getChainId();
189    if (chainid != network) {
190        switchEthereumChainWithProvider(web3obj.currentProvider, acceptedChainId)
191    }
192    
193
194    return web3obj
195}
196
197async function disconnectWalletLink(web3Modal) {
198    if (provider.close) {
199        await provider.close();
200        await provider.disconnect();
201        // If the cached provider is not cleared,
202        // WalletConnect will default to the existing session
203        // and does not allow to re-scan the QR code with a new wallet.
204        // Depending on your use case you may want or want not his behavir.
205        //await web3Modal.clearCachedProvider();
206        provider = null;
207        window.location.reload(true);
208    }
209}
210
211
212// Defi wallet - This function only apply to Cronos
213async function initialDefiWallet(strNetId, SiteNetChainId, SitePublicRpcUrl) {
214    var walletConnectObj = new window.DeFiConnect.DeFiWeb3Connector({
215        supportedChainIds: [strNetId],
216        rpc: {
217
218            [SiteNetChainId]: SitePublicRpcUrl
219        },
220        pollingInterval: 15000
221    });
222
223    return walletConnectObj
224}
225
226async function connectDefiWallet(walletConnectObj) {
227    await walletConnectObj.activate();
228    provider = await walletConnectObj.getProvider();
229    web3obj = new Web3(provider);
230
231    return web3obj
232}
233
234async function exitProvider(walletConnectObj_v2) {
235    if (provider) {
236        await provider.close();
237        // If the cached provider is not cleared,
238        // WalletConnect will default to the existing session
239        // and does not allow to re-scan the QR code with a new wallet.
240        // Depending on your use case you may want or want not his behavir.
241        //await web3Modal.clearCachedProvider();
242        provider = null;
243        window.location.reload(true);
244    }
245
246    if (walletConnectObj_v2) {
247        await walletConnectObj_v2.disconnect();
248        window.location.reload(true);
249    }
250}
251
252async function getDetailsFromMetamask() {
253    try {
254        if (!isMetamaskInstalled()) {
255            return null;
256        }
257
258        var accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
259        if (accounts.length == 0) {
260            return null;
261        }
262
263        var account = accounts[0]
264        var chainId = ethereum.chainId
265
266        return { account, chainId };
267    } catch (error) {
268        return null;
269    }
270}
271
272async function getDetailsFromMetamaskWithProvider(provider) {
273    try {
274        if (!isMetamaskInstalled()) {
275            return null;
276        }
277
278        var accounts = await provider.request({ method: 'eth_requestAccounts' });
279        if (accounts.length == 0) {
280            return null;
281        }
282
283        var account = accounts[0]
284        var chainId = provider.chainId
285
286        return { account, chainId };
287    } catch (error) {
288        return null;
289    }
290}
291
292async function getDetailsFromProvider(provider) {
293    try {
294        var accounts = await provider.request({ method: 'eth_requestAccounts' });
295        if (accounts.length == 0) {
296            return null;
297        }
298
299        var account = accounts[0]
300        var chainId = provider.chainId
301
302        return { account, chainId };
303    } catch (error) {
304        return null;
305    }
306}
307
308function isMetamaskInstalled() {
309    return window.ethereum && window.ethereum.isMetaMask;
310}
311
312async function checkWeb3WalletProvider(providerName) {
313    var rtnCheck = 0;
314    let SelectedProvider = providers.find((p) => p.info.name == providerName);
315
316    // if provider available then use the provider for web3 injection, else use general web3.ethereum 
317    if (typeof SelectedProvider !== 'undefined') {
318        rtnCheck = 1;
319    }
320    return rtnCheck;
321}
322
323function createContract(web3, abi, account, data) {
324    var contract = web3.eth.contract(abi);
325
326    web3.eth.estimateGas({
327        from: account,
328        data: data
329    }, function (error, estimatedGas) {
330        var gasfee;
331        if (!error) {
332            gasfee = estimatedGas
333        }
334        else {
335            gasfee = '5000000';
336        }
337
338        contract.new(
339            {
340                from: account,
341                data: data,
342                gas: gasfee
343            }, function (e, contract) {
344                //if (typeof contract.address !== 'undefined') {
345                //console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
346                //}
347            });
348    });
349}
350
351function registerMetamaskEvents() {
352    window.ethereum.on('accountsChanged', async (accounts) => {
353        walletDetails.account = accounts[0];
354    });
355
356    window.ethereum.on('chainChanged', function (chainId) {
357        var flag = false;
358        if (chainId.toLowerCase() != acceptedChainId.toLowerCase()) {
359            alert("Please connect to " + mainnetName + " network");
360            flag = true;
361        }
362
363        if (flag) {
364            window.location.reload();
365        }
366    });
367}
368
369function registerMetamaskEventsWithProvider(provider) {
370    provider.on('accountsChanged', async (accounts) => {
371        walletDetails.account = accounts[0];
372    });
373
374    provider.on('chainChanged', function (chainId) {
375        var flag = false;
376        if (chainId != acceptedChainId) {
377            alert("Please connect to " + mainnetName + " network");
378            flag = true;
379        }
380
381        if (flag) {
382            window.location.reload();
383        }
384    });
385}
386
387function switchEthereumChain(acceptedChainId) {
388    return window.ethereum.request({
389        method: 'wallet_switchEthereumChain',
390        params: [{ chainId: acceptedChainId }], // chainId must be hexadecimal.
391    });
392}
393
394function switchEthereumChainWithProvider(provider, acceptedChainId) {
395    return provider.request({
396        method: 'wallet_switchEthereumChain',
397        params: [{ chainId: acceptedChainId }], // chainId must be hexadecimal.
398    });
399}
400
401function addEthereumChain(acceptedChainId, mainnetName, strSymbol, strRpcUrl, strExplorerUrl, decimal) {
402    let p = [{
403        chainId: acceptedChainId,
404        chainName: mainnetName,
405        nativeCurrency: {
406            name: strSymbol,
407            symbol: strSymbol,
408            decimals: decimal
409        },
410        rpcUrls: [strRpcUrl],
411        blockExplorerUrls: [strExplorerUrl]
412    }]
413
414    return window.ethereum.request({ method: 'wallet_addEthereumChain', params: p });
415}
416
417
418function addEthereumChainWithProvider(acceptedChainId, mainnetName, strSymbol, strRpcUrl, strExplorerUrl, decimal, provider) {
419    let p = [{
420        chainId: acceptedChainId,
421        chainName: mainnetName,
422        nativeCurrency: {
423            name: strSymbol,
424            symbol: strSymbol,
425            decimals: decimal
426        },
427        rpcUrls: [strRpcUrl],
428        blockExplorerUrls: [strExplorerUrl]
429    }]
430
431    return provider.request({ method: 'wallet_addEthereumChain', params: p });
432}
433
434function walletErrorIndicatesMissingChain(error) {
435    if (error == null) return false;
436    if (error.code === 4902) return true;
437    if (error.data == null) return false;
438
439    // Rabby..... puts the error here....
440    if (error.data.originalError != null) {
441        if (error.data.originalError.code === 4902) return true;
442    }
443
444    // if any other wallets do it differently we can add them here
445
446    return false;
447}
448
449//supercedes switchEthereumChainWithProvider with additional checks - eventually we should do walletlink under this as well
450async function switchOrAddEthereumChainWithProvider(provider, acceptedChainId, mainnetName, strSymbol, strRpcUrl, strExplorerUrl, decimal) {
451    try {
452        await switchEthereumChainWithProvider(provider, acceptedChainId);
453    } catch (error) {
454        if (walletErrorIndicatesMissingChain(error) === false) {
455            throw error;
456        }
457
458        await addEthereumChainWithProvider(acceptedChainId, mainnetName, strSymbol, strRpcUrl, strExplorerUrl, decimal, provider);
459        await switchEthereumChainWithProvider(provider, acceptedChainId);
460    }
461}
462
463function addEthereumTokenWithProvider(litAssetType, litAssetAddress, litAssetSymbol, litAssetDecimal, litAssetLogo, provider) {
464
465    let p = {
466        'type': litAssetType,
467        'options': {
468            'address': litAssetAddress,
469            'symbol': litAssetSymbol,
470            'decimals': litAssetDecimal,
471            'image': litAssetLogo,
472        },
473    }
474
475    return provider.sendAsync({
476        method: 'wallet_watchAsset', params: p, id: Math.round(Math.random() * 100000)
477    });
478}
479
480function GeneralRequestWithProvider(method, param, provider) {
481
482    return provider.request({ method: method, params: param });
483}
484
485
486function isInputAddress(web3, address) {
487    var isAddress = false;
488    try {
489        var checkSumAddress = web3.utils.toChecksumAddress(address);
490        isAddress = web3.utils.isAddress(checkSumAddress);
491    } catch {
492        isAddress = false
493    }
494
495    return isAddress
496}
497
498
499function getNativeChainTokenDetails(intChainId) {
500    switch (intChainId) {
501        case 56: // BNB Smart Chain Mainnet
502        case 97: // BNB Smart Chain Testnet
503            return {
504                tokenTicker: "BNB",
505                tokenName: "BNB",
506                decimals: 18
507            };
508        case 137: // Polygon Mainnet
509        case 80002: // Polygon Amoy Testnet
510            return {
511                tokenTicker: "POL",
512                tokenName: "Polygon",
513                decimals: 18
514            };
515        case 1284: // Moonbeam Mainnet
516            return {
517                tokenTicker: "GLMR",
518                tokenName: "Glimmer",
519                decimals: 18
520            };
521        case 1285: // Moonriver Mainnet
522            return {
523                tokenTicker: "MOVR",
524                tokenName: "Moonriver",
525                decimals: 18
526            };
527        case 1287: // Moonbase Alpha Testnet
528            return {
529                tokenTicker: "DEV",
530                tokenName: "Moonbase Alpha",
531                decimals: 18
532            };
533        case 25: // Cronos
534            return {
535                tokenTicker: "CRO",
536                tokenName: "Cronos",
537                decimals: 18
538            };
539        case 199: // BitTorrent Chain Mainnet
540            return {
541                tokenTicker: "BTT",
542                tokenName: "BitTorrent",
543                decimals: 18
544            };
545        case 42220: // Celo Mainnet
546        case 44787: // Celo Alfajores Testnet
547            return {
548                tokenTicker: "CELO",
549                tokenName: "Celo",
550                decimals: 18
551            };
552        case 100: // Gnosis Chain
553            return {
554                tokenTicker: "xDAI",
555                tokenName: "XDAI",
556                decimals: 18
557            };
558        case 1111: // WEMIX Mainnet
559        case 1112: // WEMIX Testnet
560            return {
561                tokenTicker: "WEMIX",
562                tokenName: "WEMIX",
563                decimals: 18
564            };
565        case 43114: // Avalanche C-Chain Mainnet
566        case 43113: // Avalanche Fuji Testnet
567            return {
568                tokenTicker: "AVAX",
569                tokenName: "Avalanche",
570                decimals: 18
571            };
572        case 50: // XDC Network
573        case 51: // XDC Apothem Network
574            return {
575                tokenTicker: "XDC",
576                tokenName: "XDC",
577                decimals: 18
578            };
579        case 146: // Sonic Mainnet
580        case 14601: // Sonic Testnet
581            return {
582                tokenTicker: "S",
583                tokenName: "Sonic",
584                decimals: 18
585            };
586        case 50104: // Sophon Mainnet
587        case 531050104: // Sophon Testnet
588            return {
589                tokenTicker: "SOPH",
590                tokenName: "Sophon",
591                decimals: 18
592            };
593        case 80094: // Berachain Mainnet
594            return {
595                tokenTicker: "BERA",
596                tokenName: "Berachain",
597                decimals: 18
598            };
599        case 4352: // Memecore Mainnet
600        case 43521: // Memecore Testnet
601            return {
602                tokenTicker: "M",
603                tokenName: "Memecore",
604                decimals: 18
605            };
606        default:
607            return {
608                tokenTicker: "ETH",
609                tokenName: "Ether",
610                decimals: 18
611            };
612    }
613}
614
615async function connectWithRabby(providerName) {
616    const walletInput = String(providerName || '').toLowerCase();
617    let nonBrowserWallet = true;
618    let web3obj = null;
619
620    const isRabbyInfo = (info) => {
621        const s = ((info?.name || '') + ' ' + (info?.rdns || '')).toLowerCase();
622        // Accepts "Rabby Wallet", "io.rabby", etc.
623        return s.includes('rabby');
624    };
625
626    // 1) Try EIP-6963-discovered Rabby first
627    try {
628        let entry = null;
629
630        // If a specific label was passed ("Rabby"), prefer entries whose name contains it;
631        // otherwise any provider that looks like Rabby.
632        if (Array.isArray(providers) && providers.length) {
633            entry = providers.find(p => // Prefer “name contains Rabby” if available
634                p?.info && isRabbyInfo(p.info) &&
635                (walletInput ? String(p.info.name || '').toLowerCase().includes(walletInput) : true)
636            ) || providers.find(p => p?.info && isRabbyInfo(p.info));
637        }
638
639        if (entry && entry.provider) {
640            web3obj = new Web3(entry.provider);
641            const provider = entry.provider;
642            const iseip6963 = true;
643            return { web3obj, provider, iseip6963, nonBrowserWallet };
644        }
645    } catch (err) {
646        console.error("connectWithRabby #1 - ", err);
647    }
648
649    // 2) Fallback: classic injected provider that identifies as Rabby
650    try {
651        if (window.ethereum && (window.ethereum.isRabby === true ||
652            window.ethereum.provider?.isRabby === true)) {
653            web3obj = new Web3(window.ethereum);
654            const provider = window.ethereum;
655            const iseip6963 = false;
656            return { web3obj, provider, iseip6963, nonBrowserWallet };
657        }
658    } catch (err) {
659        console.error("connectWithRabby #2 - ", err);
660    }
661
662    // 3) Mobile: fall back to "whatever injected provider exists" so Rabby Mobile / MetaMask-in-Rabby still work.
663    const isEIP6963Env = Array.isArray(providers) && providers.length > 0;
664    const hasInjected = typeof parent.ethereum !== 'undefined';
665    const isLikelyMobile = !isEIP6963Env && hasInjected;
666    try {
667        if (isLikelyMobile) {
668            ethereum = parent.ethereum;
669            web3obj = new Web3(parent.ethereum);
670            const provider = parent.ethereum;
671            const iseip6963 = false;
672            nonBrowserWallet = false;
673            return { web3obj, provider, iseip6963, nonBrowserWallet };
674        }
675    } catch (err) {
676        console.error("connectWithRabby #3 - ", err);
677    }
678
679    // 4) Not found → return nulls
680    return { web3obj: null, provider: null, iseip6963: false, nonBrowserWallet: null };
681}
682
683async function disconnectMmAndRabby(provider) {
684    // Reference link for the method:
685    // https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_revokepermissions
686    // https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-2.md
687    await provider.request({
688        method: 'wallet_revokePermissions',
689        params: [{ eth_accounts: {} }],
690    });
691}
692
693async function getDetailsFromRabbyWithProvider(provider) {
694    try {
695        if (!(window.ethereum && window.ethereum.isRabby)) {
696            return null;
697        }
698
699        var accounts = await provider.request({ method: 'eth_requestAccounts' });
700        if (accounts.length == 0) {
701            return null;
702        }
703
704        var account = accounts[0]
705        var chainId = provider.chainId
706
707        return { account, chainId };
708    } catch (error) {
709        return null;
710    }
711}
712
713async function connectWithOther(providerName, ps = null) {
714    const walletInput = String(providerName || '').toLowerCase();
715    let nonBrowserWallet = true;
716    let web3obj = null;
717
718    // 1) Try EIP-6963-discovered wallet
719    try {
720        let entry = null;
721
722        // get the selected wallet provider 
723        if (Array.isArray(providers) && providers.length) {
724            entry = providers.find((p) => p.info.name == providerName);
725        }
726
727        if (entry == undefined && ps != null) {
728            entry = ps.find((p) => p.info.name == providerName);
729        }
730
731        if (entry && entry.provider) {
732            web3obj = new Web3(entry.provider);
733            const provider = entry.provider;
734            const iseip6963 = true;
735            return { web3obj, provider, iseip6963, nonBrowserWallet };
736        }
737    } catch (err) {
738        console.error("connectWithOther #1 - ", err);
739        // fall through to window.ethereum fallback
740    }
741
742    // 2) Fallback: classic injected provider
743    try {
744        if (window.ethereum) {
745            web3obj = new Web3(window.ethereum);
746            const provider = window.ethereum;
747            const iseip6963 = false;
748            return { web3obj, provider, iseip6963, nonBrowserWallet };
749        }
750    } catch (err) {
751        console.error("connectWithOther #2 - ", err);
752    }
753
754    // 3) Mobile: fall back to "whatever injected provider exists"
755    const isEIP6963Env = Array.isArray(providers) && providers.length > 0;
756    const hasInjected = typeof parent.ethereum !== 'undefined';
757    const isLikelyMobile = !isEIP6963Env && hasInjected;
758    try {
759        if (isLikelyMobile) {
760            ethereum = parent.ethereum;
761            web3obj = new Web3(parent.ethereum);
762            const provider = parent.ethereum;
763            const iseip6963 = false;
764            nonBrowserWallet = false;
765            return { web3obj, provider, iseip6963, nonBrowserWallet };
766        }
767    } catch (err) {
768        console.error("connectWithOther #3 - ", err);
769    }
770
771    // 4) Not found → return nulls
772    return { web3obj: null, provider: null, iseip6963: false, nonBrowserWallet: null };
773}
774
775async function getDetailsFromOtherProvider(provider) {
776    try {
777        var accounts = await provider.request({ method: 'eth_requestAccounts' });
778        var chainId = await provider.request({ method: "eth_chainId" });
779        if (accounts.length == 0) {
780            return null;
781        }
782
783        var account = accounts[0]
784        //var chainId = provider.chainId
785
786        return { account, chainId };
787    } catch (error) {
788        return null;
789    }
790}
791
792async function revokeConnection(provider) {
793    try {
794        await provider.request({
795            method: "wallet_revokePermissions",
796            params: [{ eth_accounts: {} }],
797        });
798        return true;
799    } catch { }
800
801    try {
802        if (typeof provider.disconnect === "function") {
803            await provider.disconnect();
804            return true;
805        }
806    } catch { }
807
808    return false;
809}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.