通过获取用户地址并授权连接,您可以使用 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);
在 React 应用中,一旦建立连接,您可以使用 useWallet()
钩子获取钱包实例并签署交易。
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);
}