3

I need to retrieve some transactions from a specific account and then read the memo. I've tried a couple of different methods with no success. My first attempt was as below, but I get odd looking memo values that look like this: 1txn = org.stellar.sdk.MemoText@223d2c72 .

System.out.println("Transactions for account " + currentUser.userKeys.getAccountId());
System.out.println("And secret seed:  " +   String.valueOf(currentUser.userKeys.getSecretSeed()));
System.out.println(" ");
Server server = new Server("https://horizon-testnet.stellar.org");
TransactionsRequestBuilder txnRequests = server.transactions().forAccount(currentUser.userKeys)
    .order(RequestBuilder.Order.DESC);

List<TransactionResponse> responses = new ArrayList<>();
Page<TransactionResponse> page = txnRequests.execute();
System.out.println(page.toString());

responses.addAll(page.getRecords());
responses.forEach(txn -> {System.out.println("1txn = " + txn.getMemo());});

I read another post stating that MemoText is a class and that I should use MemoText.getText() to get the text from the transactions i receive, but can't figure out how to use the class to retrieve the memo. It would be very helpful if someone could provide a short example. Thanks in advance.

1 Answer 1

1

Memo is an abstract type that represents 5 different kinds of objects. The Java SDK does not define toString methods for these classes, so the printed output defaults to the toString method on Object. This is unhelpful, as you outlined.

In order to print the memo text you first need to identify if the memo is of the right subtype, and then you need to cast it. It's a bit ugly. e.g.

if (txn.getMemo() instanceof MemoText) {
  System.out.println(((MemoText) txn.getMemo()).getText());
} else {
  System.out.println(txn.getMemo());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.