Sign and Verify Messages
Sign messages and verify signatures with Tron accounts using secp256k1.
This guide explains how to sign messages with an owned account and verify signatures using a read-only account. Tron uses secp256k1 cryptography for signing.
Sign a Message
You can produce a cryptographic signature for any string message using account.sign():
const message = 'Hello, Tron!'
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 WalletAccountReadOnlyTron from any Tron address 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.