Kit
Functions

useWalletAccountMessageSigner

useWalletAccountMessageSigner<TWalletAccount>(uiWalletAccount): MessageModifyingSigner<TWalletAccount["address"]>

Use this to get a MessageSigner capable of signing messages with the private key of a UiWalletAccount

Type Parameters

Type Parameter
TWalletAccount extends UiWalletAccount

Parameters

ParameterType
uiWalletAccountTWalletAccount

Returns

MessageModifyingSigner<TWalletAccount["address"]>

A MessageModifyingSigner. This is a conservative assumption based on the fact that your application can not control whether or not the wallet will modify the message before signing it. Otherwise this method could more specifically return a MessageSigner or a MessagePartialSigner.

Example

import { useWalletAccountMessageSigner } from '@solana/react';
import { createSignableMessage } from '@solana/signers';
 
function SignMessageButton({ account, text }) {
    const messageSigner = useWalletAccountMessageSigner(account);
    return (
        <button
            onClick={async () => {
                try {
                    const signableMessage = createSignableMessage(text);
                    const [signedMessage] = await messageSigner.modifyAndSignMessages([signableMessage]);
                    const messageWasModified = signableMessage.content !== signedMessage.content;
                    const signatureBytes = signedMessage.signatures[messageSigner.address];
                    window.alert(
                        `Signature bytes: ${signatureBytes.toString()}${
                            messageWasModified ? ' (message was modified)' : ''
                        }`,
                    );
                } catch (e) {
                    console.error('Failed to sign message', e);
                }
            }}
        >
            Sign Message: {text}
        </button>
    );
}

On this page