WDK logoWDK documentation
SolanaStandard SolanaGuides

Sign and Verify Messages

Sign messages and verify signatures with Solana accounts using Ed25519.

This guide explains how to sign arbitrary messages with an owned account and verify signatures using a read-only account. Solana uses Ed25519 cryptography for signing.

Sign a Message

Use account.sign() to sign the UTF-8 bytes of a string. Pass the same text to verify(); a string such as '0x1234' is signed as text, not decoded as hexadecimal bytes. The returned signature is hex-encoded.

Sign a Message
const message = 'Hello, Solana!'
const signature = await account.sign(message)
console.log('Signature:', signature)

Verify a Signature

You can get a read-only account from any Account object by calling account.toReadOnlyAccount(). Use a read-only account to verify() that a signature was produced by the corresponding private key.

Verify a Signature
const readOnlyAccount = await account.toReadOnlyAccount()
const isValid = await readOnlyAccount.verify(message, signature)
console.log('Signature valid:', isValid)

You can also create a WalletAccountReadOnlySolana from any public key to verify signatures without access to the private key.

Next Steps

For best practices on handling errors, managing fees, and cleaning up memory, see Error Handling.

On this page