From 7c7d8c9247886c37e7ac416416f77a1933f568ab Mon Sep 17 00:00:00 2001 From: norlin Date: Mon, 8 Nov 2021 14:16:05 +0300 Subject: [PATCH] Update ethereum provider API from the very old legacy methods to the newer ones --- bridge/bsc.html | 7 ++++--- bridge/index.html | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bridge/bsc.html b/bridge/bsc.html index 2f596f8..18b8b39 100644 --- a/bridge/bsc.html +++ b/bridge/bsc.html @@ -734,8 +734,8 @@ } else { let myEthAddress; try { - const accounts = (await ethereum.send('eth_requestAccounts')).result; - myEthAddress = accounts[0] + const accounts = await ethereum.request({method: 'eth_requestAccounts'}); + myEthAddress = accounts[0]; console.log('address is', myEthAddress); } catch (error) { console.log(error); @@ -753,7 +753,8 @@ console.log('address is', provider.myEthAddress); }); - if (ethereum.networkVersion !== ETH_CHAIN_ID.toString()) { + const networkVersion = await ethereum.request({ method: 'net_version' }); + if (networkVersion !== ETH_CHAIN_ID.toString()) { alert('Set chain to ' + (IS_TESTNET ? 'BSC Testnet' : 'BSC') + ' in Metamask'); return null; } diff --git a/bridge/index.html b/bridge/index.html index 65f7410..0fe325c 100644 --- a/bridge/index.html +++ b/bridge/index.html @@ -732,7 +732,7 @@ } else { let myEthAddress; try { - const accounts = (await ethereum.send('eth_requestAccounts')).result; + const accounts = await ethereum.request({method: 'eth_requestAccounts'}); myEthAddress = accounts[0] console.log('address is', myEthAddress); } catch (error) { @@ -751,7 +751,8 @@ console.log('address is', provider.myEthAddress); }); - if (ethereum.networkVersion !== ETH_CHAIN_ID.toString()) { + const networkVersion = await ethereum.request({ method: 'net_version' }); + if (networkVersion !== ETH_CHAIN_ID.toString()) { alert('Set chain to ' + (ETH_CHAIN_ID === 3 ? 'Ropsten' : 'Mainnet') + ' in Metamask'); return null; }