With access to the user address and the connection authorized, you can request the user's signature using signMessage()
.
1const account = await fuel.currentAccount();
2if (!account) {
3 throw new Error("Current account not authorized for this connection!");
4}
5const wallet = await fuel.getWallet(account);
6const signedMessage = await wallet.signMessage(message);
7console.log("Message signature", signedMessage);
In a React app, once the connection is established, you can use the useWallet()
hook to get a wallet instance and sign the transaction.
1const { wallet } = useWallet();
2
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);
10}