Js read note field from a txn

Hello guys,

I need the content of note field in json from a txn. Using this code as example:

            .then(transaction => {
              if (transaction) {
                console.log('transaction found.');
                console.log('detail txn:', transaction);

                // read "note" inside txn
                const note = algosdk.decodeObj(transaction.txn.tx.note);
                console.log('note data:', note);

                // On web page
                const resultDiv = document.getElementById('result');
                resultDiv.innerHTML = `
                  <p>Txn is present on blockchain.</p>
                  <p>detail txn:</p>
                  <pre>${JSON.stringify(transaction, null, 2)}</pre>
                  <p>Value of  "note": ${note}</p>

but I receive this error :

Cannot read properties of undefined (reading ‘note’).

the note data is in JSON.

Thank’s in advance


p.s. sorry, js isn’t my preferred language

I think it’s transaction.txn.note but best is to print the object transaction.txn, something like console.log(JSON.stringify(transaction)) so you can see how it looks like.

Hi Fabrice,

thanks for suggestion.

Now , this work !

 function readAlgorandTransaction(transactionID) {
          .then(response => response.json())
          .then(data => {
            const note = data.transaction.note;
            const content = atob(note);
            const content_dati = JSON.parse(content);

            // print result
            const resultDiv = document.getElementById('result');

            const resultText = `Result of reading:<br><span id="name">${content_dati.firstName}</span> <span id="surname">${content_dati.lastName}</span><br>`;
            resultDiv.innerHTML = resultText;


p.s. simple solution is better solution :slight_smile:

1 Like