Docs Icon ChevronRight For Developers Icon ChevronRight Signing a Message

Signing a Message

With access to the user address and the connection authorized, you can request the user's signature using signMessage().

SignMessage.tsx Icon Link
1const account = await fuel.currentAccount();
2if (!account) {
3  throw new Error("Current account not authorized for this connection!");
5const wallet = await fuel.getWallet(account);
6const signedMessage = await wallet.signMessage(message);
7console.log("Message signature", signedMessage);

With React

In a React app, once the connection is established, you can use the useWallet() hook to get a wallet instance and sign the transaction.

SignMessageHook.tsx Icon Link
1const { wallet } = useWallet();
3async function handleSignMessage(message: string) {
4  console.log("Request signature of message!");
5  if (!wallet) {
6    throw new Error("Current wallet is not authorized for this connection!");
7  }
8  const signedMessage = await wallet.signMessage(message);
9  console.log("Message signature", signedMessage);