5

It seems the the transactions for account will give you back a memo, but no way to get the payments info such as the amount without making another API call on the individual payment for transaction.

Right now I am just getting the list of payments for the account but I also want to display the memo. Is there some kind of undocumented include query on the transactions API so it will include payments with it?

3 Answers 3

4

The detail of a transaction's operations are encoded in the field envelope_xdr. You can decode this value to obtain the payments and other operations.

For example, this transaction with memo "Fruitcakes for Iguanas" has an envelope_xdr that decodes to show the payment details.

So if you can approach your problem by fetching transactions instead of payments you'll have all the data you need in a single call.

1
  • This is great! I didn't think of this solution but this seems like the best approach to have a complete picture of every transaction in a single call. Thanks!
    – aasatt
    Jun 12, 2018 at 17:59
3

The memo is associated with the transaction, so you'll have to actually pull the transaction for each payment.

Here is some code for how I've handled it in the past with the JS SDK:

function watchForPayments(publicKey, { onPayment, cursor }) {
  const paymentsCallBuilder = server.payments().forAccount(publicKey);

  if (cursor) {
    paymentsCallBuilder.cursor(cursor);
  }

  return paymentsCallBuilder.stream({
    onmessage: async record => {
      const transaction = await record.transaction();

      onPayment({
        memo: transaction.memo,
        amount: record.amount,
        createdAt: new Date(record.created_at),
        asset: record.asset_type,
        cursor: record.paging_token,
        to: record.to,
        from: record.from,
        hash: record.transaction_hash
      });
    }
  });
}

The key part is const transaction = await record.transaction();, which makes another request to get the transaction (which contains the memo) associated with the operation.

1
  • Thank you for the detailed answer. However, my main goal of this question was to find a solution that doesn't involve multiple round trips to the REST API.
    – aasatt
    Jun 12, 2018 at 17:56
2

I've made Payment Locator tool with public API that exactly matches your case.

Some highlights:

  • Lookup by transaction memo, amount, asset, source/destination account.
  • Search by a single parameter or a complex criteria.
  • All operations are supported: PAYMENT, PATH_PAYMENT, CREATE_ACCOUNT, MERGE_ACCOUNT.
  • Find everything, no matter how long ago operations were submitted.
  • Works even with deleted(merged) accounts.

If you don't need the API, you can search for payments using simple UI form directly from the browser.

1
  • Hi. This looks promising although I want to limit my dependencies on 3rd party APIs. My ideal solution is to limit all networking activity to the horizon network. If the envelope_xdr solution that @synesso provided doesn't work out I may have to go this route though.
    – aasatt
    Jun 12, 2018 at 18:03

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.