Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Signing a Message

Icon LinkSigning a Message

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

const account = await fuel.currentAccount();
if (!account) {
  throw new Error("Current account not authorized for this connection!");
}
const wallet = await fuel.getWallet(account);
const signedMessage = await wallet.signMessage(message);
console.log("Message signature", signedMessage);

Icon LinkWith 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.

const { wallet } = useWallet();
 
async function handleSignMessage(message: string) {
  console.log("Request signature of message!");
  if (!wallet) {
    throw new Error("Current wallet is not authorized for this connection!");
  }
  const signedMessage = await wallet.signMessage(message);
  console.log("Message signature", signedMessage);
}