Skip to main content

useSignMessage

Hook to sign a message.

Usage

import { useAccounts, useSignMessage } from '@kibisis/katavault-react';

function SignMessage() {
const accounts = useAccounts();
const signMessage = useSignMessage();
const handleOnSignMessageClick = (address: string) => () => {
signMessage({
address,
encoding: 'hex',
message: 'hello humie!',
}, {
onError: (error) => {
console.error(error);
},
onSuccess: (result: string) => {
console.log(`signed message with signature: ${result}`);
},
});
};

return (
<div>
{accounts.map(({ address, name }) => (
<div>
<p>Address: {address}</p>
<p>Name: {name ?? '-'}</p>
<button onClick={handleOnSignMessageClick(address)}>Remove</button>
</div>
))}
</div>
);
}

Returns

(params: SignParameters, options?: { onError, onSuccess }) => void

The function can be called with callbacks that are invoked on error/success.

onError

(error: BaseError, params: SignParameters) => void | Promimse<void>

This will be invoked if there was an error.

onSuccess

(result: string | Uint8Array, params: SignParameters) => void | Promimse<void>

This will be invoked with the signature as the result if the message signing was successful.

note

If the params.encoding are used, the result will be a string in the specified encoding. Otherwise, the raw signature bytes will be returned.

See also