|
40 | 40 | "0x1": "Ethereum mainnet", |
41 | 41 | "0x3": "Ropsten", |
42 | 42 | "0x4": "Rinkeby", |
43 | | - "0x5": "Görli", |
| 43 | + "0xaa36a7": "Sepolia", |
44 | 44 | "0x2a": "Kovan" |
45 | 45 | } |
46 | 46 |
|
47 | 47 | const chainPrefixes = { |
48 | 48 | "0x1": "", |
49 | 49 | "0x3": "ropsten.", |
50 | 50 | "0x4": "rinkeby.", |
51 | | - "0x5": "goerli.", |
| 51 | + "0xaa36a7": "sepolia.", |
52 | 52 | "0x2a": "kovan." |
53 | 53 | } |
54 | 54 |
|
55 | 55 | const chainApiPrefixes = { |
56 | 56 | "0x1": "", |
57 | 57 | "0x3": "-ropsten", |
58 | 58 | "0x4": "-rinkeby", |
59 | | - "0x5": "-goerli", |
| 59 | + "0xaa36a7": "-sepolia", |
60 | 60 | "0x2a": "-kovan" |
61 | 61 | } |
62 | 62 |
|
63 | | -const infuraPrefixes = { |
| 63 | +const chainSuffixes = { |
64 | 64 | "0x1": "mainnet", |
65 | 65 | "0x3": "ropsten", |
66 | 66 | "0x4": "rinkeby", |
67 | | - "0x5": "goerli", |
| 67 | + "0xaa36a7": "sepolia", |
68 | 68 | "0x2a": "kovan" |
69 | 69 | } |
70 | 70 |
|
|
79 | 79 | }, draw); |
80 | 80 | } |
81 | 81 |
|
82 | | -let provider, chain, chainPrefix, chainApiPrefix, infuraPrefix, notice; |
| 82 | +let provider, chain, chainPrefix, chainApiPrefix, chainSuffix, notice; |
83 | 83 | window.addEventListener("load", () => { |
84 | 84 | if (typeof window.ethereum !== "undefined") { |
85 | 85 | setTimeout(() => { |
86 | 86 | if (!window.ethereum.isConnected()) { |
87 | | - console.log("Metamask connection timed out. Falling back to Infura mainnet"); |
88 | | - setInfura(); |
| 87 | + console.log("Metamask connection timed out. Falling back to TechOps mainnet"); |
| 88 | + setDefaultRPC(); |
89 | 89 | } |
90 | 90 | }, 1000); |
91 | 91 | window.ethereum.on("connect", conn => { |
|
94 | 94 | if (!chain) chain = "Unknown"; |
95 | 95 | chainPrefix = chainPrefixes[conn.chainId]; |
96 | 96 | chainApiPrefix = chainApiPrefixes[conn.chainId]; |
97 | | - infuraPrefix = infuraPrefixes[conn.chainId]; |
98 | | - endpoint = "https://" + infuraPrefix + ".infura.io/v3/633f64adbe364bb88127348d4fcc21ef"; |
| 97 | + chainSuffix = chainSuffixes[conn.chainId]; |
| 98 | + endpoint = chainSuffix === "mainnet" ? "https://chain.techops.live/eth-mainnet" : "https://chain.techops.live/eth-" + chainSuffix; |
99 | 99 | notice = "change this in your Metamask plugin (you don’t need to unlock Metamask)"; |
100 | 100 | setUp(); |
101 | 101 | }); |
|
104 | 104 | if (!chain) chain = "Unknown"; |
105 | 105 | chainPrefix = chainPrefixes[chainId]; |
106 | 106 | chainApiPrefix = chainApiPrefixes[chainId]; |
107 | | - infuraPrefix = infuraPrefixes[chainId]; |
108 | | - endpoint = "https://" + infuraPrefix + ".infura.io/v3/633f64adbe364bb88127348d4fcc21ef"; |
| 107 | + chainSuffix = chainSuffixes[chainId]; |
| 108 | + endpoint = chainSuffix === "mainnet" ? "https://chain.techops.live/eth-mainnet" : "https://chain.techops.live/eth-" + chainSuffix; |
109 | 109 | notice = ""; |
110 | 110 | setUp(); |
111 | 111 | }); |
112 | 112 | } else { |
113 | | - setInfura(); |
| 113 | + setDefaultRPC(); |
114 | 114 | } |
115 | 115 | }); |
116 | 116 |
|
117 | | -const setInfura = () => { |
118 | | - provider = "Infura"; |
| 117 | +const setDefaultRPC = () => { |
| 118 | + provider = "TechOps"; |
119 | 119 | chain = "Ethereum mainnet"; |
120 | 120 | chainPrefix = ""; |
121 | 121 | chainApiPrefix = ""; |
122 | | - infuraPrefix = "mainnet"; |
| 122 | + chainSuffix = "mainnet"; |
123 | 123 | notice = ""; |
124 | 124 | chainSelect.removeAttribute("disabled"); |
125 | | - chainSelect.append(chainGoerli); |
| 125 | + chainSelect.append(chainSepolia); |
126 | 126 | setUp(); |
127 | 127 | } |
128 | 128 |
|
|
170 | 170 | chainOption.innerHTML = "loading…"; |
171 | 171 | chainOption.setAttribute("value", "mainnet"); |
172 | 172 | chainSelect.append(chainOption); |
173 | | -const chainGoerli = document.createElement("option"); |
174 | | -chainGoerli.innerHTML = "Görli"; |
175 | | -chainGoerli.setAttribute("value", "goerli"); |
| 173 | +const chainSepolia = document.createElement("option"); |
| 174 | +chainSepolia.innerHTML = "Sepolia"; |
| 175 | +chainSepolia.setAttribute("value", "sepolia"); |
176 | 176 | chainSelect.addEventListener("change", () => { |
177 | | - infuraPrefix = chainSelect.value; |
178 | | - chainPrefix = infuraPrefix === "mainnet" ? "" : "goerli."; |
179 | | - chainApiPrefix = infuraPrefix === "mainnet" ? "" : "-goerli"; |
180 | | - endpoint = "https://" + infuraPrefix + ".infura.io/v3/633f64adbe364bb88127348d4fcc21ef"; |
| 177 | + chainSuffix = chainSelect.value; |
| 178 | + chainPrefix = chainSuffix === "mainnet" ? "" : "sepolia."; |
| 179 | + chainApiPrefix = chainSuffix === "mainnet" ? "" : "-sepolia"; |
| 180 | + endpoint = chainSuffix === "mainnet" ? "https://chain.techops.live/eth-mainnet" : "https://chain.techops.live/eth-" + chainSuffix; |
181 | 181 | setUp(); |
182 | 182 | }); |
183 | 183 | chainValue.append(chainSelect); |
|
191 | 191 | canvas.innerHTML = "loading…"; |
192 | 192 | document.body.append(canvas); |
193 | 193 |
|
194 | | -let endpoint = 'https://mainnet.infura.io/v3/633f64adbe364bb88127348d4fcc21ef'; |
| 194 | +let endpoint = 'https://chain.techops.live/eth-mainnet'; |
195 | 195 | const chainlog = "0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F"; |
196 | 196 |
|
197 | 197 | const hex2a = hexx => { // adapted from https://stackoverflow.com/a/3745677/15857007 |
|
205 | 205 | return str; |
206 | 206 | } |
207 | 207 |
|
208 | | -const infuraCall = (params, callback) => { |
| 208 | +const rpcCall = (params, callback) => { |
209 | 209 | const options = { |
210 | 210 | method: "POST", |
| 211 | + headers: { |
| 212 | + "Content-Type": "application/json" |
| 213 | + }, |
211 | 214 | body: '{"jsonrpc": "2.0", "method": "eth_call", "params": [' + JSON.stringify(params) + ', "latest"], "id": 0}' |
212 | 215 | }; |
213 | 216 | fetch(endpoint, options).then(response => { |
214 | 217 | if (response.ok) { |
215 | 218 | response.json().then(content => callback(content.result)) |
216 | 219 | } else { |
217 | 220 | response.json().then(content => { |
218 | | - console.error("Infura: " + content.error.message); |
| 221 | + console.error("RPC: " + content.error.message); |
219 | 222 | canvas.innerHTML = "error"; |
220 | 223 | }); |
221 | 224 | } |
|
229 | 232 | params: [ params, "latest" ] |
230 | 233 | }).then(response => callback(response)) |
231 | 234 | .catch(error => { |
232 | | - console.log("falling back to Infura " + infuraPrefix); |
233 | | - infuraCall(params, callback) |
| 235 | + console.log("falling back to TechOps RPC " + chainSuffix); |
| 236 | + rpcCall(params, callback) |
234 | 237 | }); |
235 | 238 | } else { |
236 | | - infuraCall(params, callback); |
| 239 | + rpcCall(params, callback); |
237 | 240 | } |
238 | 241 | } |
239 | 242 |
|
|
0 commit comments