import { useTurnkey } from "@turnkey/react-wallet-kit";
function SignRawPayloadButton() {
const { httpClient, wallets } = useTurnkey();
const doSignRawPayload = async () => {
try {
const signWith = wallets[0]?.accounts[0].address; // Use the address of the first account of the first wallet
const message = "Hello, Turnkey!";
const hashedMessage = Buffer.from(message, "utf8").toString("hex"); // Convert message to hex format
const response = await httpClient.signRawPayload({
signWith,
payload: hashedMessage,
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
hashFunction: "HASH_FUNCTION_NOT_APPLICABLE",
});
const signature = {response.r, response.s, response.v}; // Extract the signature from the response
console.log("Message signed:", signature);
} catch (error) {
console.error("Error signing message:", error);
}
};
return <button onClick={doSignRawPayload}>Sign Message</button>;
}