Skip to content

Instantly share code, notes, and snippets.

@michojekunle
Created December 5, 2024 15:36
Show Gist options
  • Select an option

  • Save michojekunle/c10ff0a627ecfd59f9bb2c59292feb05 to your computer and use it in GitHub Desktop.

Select an option

Save michojekunle/c10ff0a627ecfd59f9bb2c59292feb05 to your computer and use it in GitHub Desktop.
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