MCPcopy Create free account
hub / github.com/Modulus-Labs/RockyBot / getCurrentWalletConnected

Function getCurrentWalletConnected

front-end/src/util/interact.ts:165–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

163 * once before and Metamask within browser saves this.
164 */
165export const getCurrentWalletConnected = async () => {
166 if (window.ethereum) {
167 try {
168 const addressArray = await window.ethereum.request({
169 method: "eth_accounts",
170 });
171
172 // --- If wallet is already connected ---
173 if (addressArray.length > 0) {
174 return {
175 address: addressArray[0],
176 status: "Your wallet has been connected!",
177 }
178
179 // --- Otherwise, prompt user to connect ---
180 } else {
181 return {
182 address: null,
183 status: "Connect to MetaMask using the top right button.",
184 }
185 }
186 } catch (error: any) {
187 return {
188 address: null,
189 status: error.message,
190 }
191 }
192
193 // --- Similarly, on user needing to install Metamask with eth ---
194 } else {
195 return {
196 address: "",
197 status: "You must install MetaMask, a virtual Ethereum wallet, in your browser."
198 }
199 }
200};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected