-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.html
75 lines (67 loc) · 2.52 KB
/
4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MetaMask Chain Switch</title>
<script>
document.addEventListener('DOMContentLoaded', function () {
if (typeof window.ethereum !== 'undefined') {
console.log('MetaMask is installed!');
} else {
alert("Please install MetaMask!");
}
});
async function switchChain(chainId) {
if (!window.ethereum) {
alert("MetaMask is not available!");
return;
}
const hexChainId = '0x' + chainId.toString(16);
try {
await window.ethereum.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: hexChainId }]
});
} catch (switchError) {
console.error(switchError);
alert("Error switching chain. Please add the chain first if it is not already added.");
}
}
async function addChain(chainId, chainName, rpcUrl, explorer, currencySymbol) {
const hexChainId = '0x' + chainId.toString(16);
try {
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [{
chainId: hexChainId,
chainName: chainName,
nativeCurrency: {
name: currencySymbol,
symbol: currencySymbol,
decimals: 18
},
rpcUrls: [rpcUrl],
blockExplorerUrls: [explorer]
}]
});
} catch (addError) {
console.error(addError);
alert("Error adding chain.");
}
}
</script>
</head>
<body>
<h1>Blockchain Seminar</h1>
<button onclick="addChain(11155111, 'Sepolia', 'https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID', 'https://sepolia.etherscan.io', 'ETH')">Add Sepolia</button>
<button onclick="switchChain(11155111)">Switch to Sepolia</button><br><br>
<a href="https://testnet.parallel.fi/bridge/">Parallel Bridge</a><br>
<button onclick="addChain(17000, 'Holesky', 'https://ethereum-holesky-rpc.publicnode.com', 'https://holesky.etherscan.io', 'ETH')">Add Holesky</button>
<button onclick="switchChain(17000)">Switch to Holesky</button><br><br>
<a href="https://bridge.hekla.taiko.xyz/">Taiko Bridge</a><br>
<button onclick="addChain(9659, 'Parallel Testnet', 'https://rpc-accused-coffee-koala-b9fn1dik76.t.conduit.xyz', 'https://explorerl2new-accused-coffee-koala-b9fn1dik76.t.conduit.xyz', 'ETH')">Add Parallel Testnet</button>
<button onclick="switchChain(9659)">Switch to Parallel Testnet</button><br><br>
<a href="https://testnet.parallel.fi/parallel_testnet/">Parallel</a><br>
</body>
</html>