Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Verify signed algosdk transaction (javascript)
const algosdk = require('algosdk');
const nobleEd25519 = require('@noble/ed25519');
// setup connection to algoexplorer API
const algodClient = new algosdk.Algodv2("", '', '');
// generate a standalone account
const account = algosdk.generateAccount();
(async () => {
// create a transaction that will be signed
const params = await algodClient.getTransactionParams().do();
const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
suggestedParams: {
from: account.addr,
to: account.addr,
amount: 0
// sign and decode transaction
const sTxn = algosdk.signTransaction(txn,
const dTxn = algosdk.decodeSignedTransaction(sTxn.blob)
// decode address to get the public key
const dAddr = algosdk.decodeAddress(account.addr);
const publicKey = dAddr.publicKey
// get the bytes to sign from the transaction
const hTxn = Buffer.from(txn.bytesToSign()).toString('hex');
// get the signature from the signed transaction
const sig = Buffer.from(dTxn.sig)
// verify signature
const verified = await nobleEd25519.verify(sig, hTxn, publicKey);
// log verification status (should be true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment