Skip to content

Commit

Permalink
Metamask chainId request({method: 'net_version'})
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz committed Jul 23, 2024
1 parent c1b8dc5 commit 52e7a33
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,18 @@ async function getAccount() {
async function enableMetamaskOnSepolia() {
//Get account details from Metamask wallet.
getAccount();

// Updated chainId request method suggested by Metamask.
let chainIdConnected = await window.ethereum.request({method: 'net_version'});

// // Outdated chainId request method which might get deprecated:
// // https://github.com/MetaMask/metamask-improvement-proposals/discussions/23
// let chainIdConnected = window.ethereum.networkVersion;

console.log("chainIdConnected: " + chainIdConnected)

//Check if user is on the Sepolia testnet. If not, alert them to change to Sepolia.
if(window.ethereum.networkVersion != baseSepoliaChainId){
if(chainIdConnected != baseSepoliaChainId){
// alert("You are not on the Sepolia Testnet! Please switch to Sepolia and refresh page.")
try{
await window.ethereum.request({
Expand Down

0 comments on commit 52e7a33

Please sign in to comment.