TransWikia.com

How to pull memo from a public key's historical transactions and save to an array?

Stellar Asked by newdev on August 21, 2021

Using Stellar’s Javascript SDK

Goal

Output an array containing all the memos:
['324567567', 'anotherMemo', '239210923', '2349028509']

This array will be used to check against a database and confirm transactions.

Problem

I have isolated the memos from every transaction; although, the output is delineated by newlines. My attempts with join() and a for-loop are unsuccessful.

My Code

var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

const hostAccountId = "GDUBG6QT24UYGBIAKRIVDA776STGIFM4XMHTAYGHOSCR44JIKN64JDKG" // Load hostAccountId from database ("test value")

server.transactions()
    .forAccount(hostAccountId)
    .limit(200)
    .order('desc')
    .call()
    .then(function (page) {
      page.records.forEach( function(record) {
        if (record.memo === undefined) {} else {
          var memo;
          memo = (record.memo);
          console.log(memo);
        }
});
    })
    .catch(function (err) {
        console.log(err);
    });

Output:

18446744073709551615
12345678910
Another Memo
Special Memo only
What does this memo say

Background

I am very new to Javascript and to programming on Stellar. Thank you for your time!

One Answer

Instantiate an empty array with

let memos = [];

And add an element with the push method.

memos.push( memo );

Snippet:

  let memos = [];
  page.records.forEach( function(record) {
    if (record.memo === undefined) {} else {
      var memo;
      memo = (record.memo);
      memos.push(memo);
    }
  })
  console.log(memos);

Correct answer by sui on August 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP