Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
You can sign a message with a wallet account by calling the signMessage function.
See Checking Wallet Account Availability for more information.
Usage
import { signMessage } from '@dynamic-labs-sdk/client';
const handleSignMessage = async () => {
try {
const { signature } = await signMessage({ walletAccount, message: 'Hello, world!' });
console.log(signature);
} catch (error) {
console.error(error);
// You might want to prompt user to reconnect or make the required wallet account active in their wallet app
}
};
import { signMessage, type WalletAccount } from '@dynamic-labs-sdk/client';
import { useState } from 'react';
function SignMessageButton({ walletAccount }: { walletAccount: WalletAccount }) {
const [signature, setSignature] = useState<string | null>(null);
const [isSigning, setIsSigning] = useState(false);
const handleSign = async () => {
setIsSigning(true);
try {
const { signature } = await signMessage({ walletAccount, message: 'Hello, world!' });
setSignature(signature);
} catch (error) {
console.error(error);
} finally {
setIsSigning(false);
}
};
return (
<div>
<button onClick={handleSign} disabled={isSigning}>
{isSigning ? 'Signing…' : 'Sign message'}
</button>
{signature && <p>Signature: {signature}</p>}
</div>
);
}
Error Handling
If the wallet account you trying to sign the message with is not connected and active in the wallet app, the function will throw a WalletAccountNotSelectedError error.
The error contains an expectedAddress, which is the address that you are trying to sign the message with, and a selectedAddress, which is the address that is currently active in the wallet app.
If there is no selectedAddress prop, it probably means that there is no connected wallet accounts to your app.