Skip to Content
dApps
On this page

Signing

Connect the provider before signing. The transaction examples use the algosdk 2-style from/to fields; match the SDK major version you install. algodClient, addresses, and grouped transactions must be prepared before running the snippets. Browser examples using Buffer need an explicit buffer import or an equivalent base64 encoder.

Learn how to sign messages for authentication on Algorand.


Sign Arbitrary Message

const message = new TextEncoder().encode('Hello Algorand!') const { signature, address } = await provider.signMessage( message, 'utf8' // or 'hex' ) console.log('Signature:', signature) console.log('Signer:', address)

Verify Signature

import nacl from 'tweetnacl' const message = new TextEncoder().encode('Hello Algorand!') const { signature } = await provider.signMessage(message) // Get public key from address const publicKey = algosdk.decodeAddress(provider.address).publicKey const isValid = nacl.sign.detached.verify(message, signature, publicKey) console.log('Valid:', isValid)

Error Handling

try { const signedTxns = await provider.signTxns(walletTxns) } catch (error) { if (error.code === 4001) { console.log('User rejected the request') } else if (error.code === 4100) { console.log('The account or method is not authorized') } else { console.error('Error:', error.message) } }

Common Error Codes

CodeDescription
4001User rejected request
4100Unauthorized
4200Unsupported method
-32602Invalid parameters
Last updated on