Skip to content

Commit

Permalink
Add getChainId method
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillweston committed Mar 31, 2024
1 parent 0f1c1fa commit ca94d1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ This section provides guidance on deploying your project to GitHub Pages and Clo
- **`CONTRACT_ADDRESS`**
- **`WEB_ADDRESS`**
- **`TURNSTILE_SITE_KEY`**
- **`INFURA_API_KEY`**
### Setting Environment Variables in GitHub
Expand Down
10 changes: 9 additions & 1 deletion js/claim-airdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ async function initiateTransaction() {
displayMessage('Waiting for user confirmation', 'info');

try {
const chainId = await window.ethereum.request({ method: 'eth_chainId' });
let chainId;
try {
chainId = await web3.eth.getChainId();
} catch (error) {
console.error("Error fetching chain ID with web3:", error);
// Fallback: Try MetaMask's eth_chainId
chainId = await window.ethereum.request({ method: 'eth_chainId' });
}

const isBaseSepolia = chainId === '0x14a34' && activeNetwork === 'baseSepolia';
const isMainnet = chainId === '0x2105' && activeNetwork === 'baseMainnet';
const isSepolia = chainId === '0xaa36a7' && activeNetwork === 'sepolia';
Expand Down

0 comments on commit ca94d1a

Please sign in to comment.