Created
December 5, 2024 15:36
-
-
Save michojekunle/c10ff0a627ecfd59f9bb2c59292feb05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useAccount, useSignMessage } from "wagmi"; | |
| import { useConnect } from "wagmi"; | |
| import { Button } from "./ui/button"; | |
| import { injected } from "wagmi/connectors"; | |
| import { liskSepolia } from "viem/chains"; | |
| const ConnectAndSign = () => { | |
| const { connectAsync } = useConnect(); | |
| const { signMessageAsync } = useSignMessage(); | |
| const { isConnected, address } = useAccount(); | |
| const handleClick = async () => { | |
| if (isConnected) return alert("Wallet connected already"); | |
| try { | |
| await connectAsync({ | |
| chainId: liskSepolia.id, | |
| connector: injected(), | |
| }); | |
| await signMessageAsync({ message: "Sign a message" }) | |
| } catch (error) { | |
| alert(error); | |
| } | |
| }; | |
| return <Button onClick={handleClick}>Connect and Sign</Button>; | |
| }; | |
| export default ConnectAndSign; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment