Sign and Verify Messages
Sign messages and verify signatures with TON accounts.
This guide explains how to sign messages with an owned account and verify signatures using a read-only account.
Sign a Message
You can produce a cryptographic signature for any string message using account.sign():
const message = 'Hello, TON!'
const signature = await account.sign(message)
console.log('Signature:', signature)Verify a Signature
You can verify that a signature was produced by the corresponding private key using readOnlyAccount.verify():
const readOnlyAccount = await account.toReadOnlyAccount()
const isValid = await readOnlyAccount.verify(message, signature)
console.log('Signature valid:', isValid)You can also create a WalletAccountReadOnlyTon 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 Handle Errors.