Reading transactions from an account

Get the list of transactions where an account is involved.

Prerequisites

Let’s get into some code

In this example, you will fetch the latest confirmed transactions for a given account using the accountHttp repository.

const accountHttp = new AccountHttp('http://localhost:3000');

const publicKey = '7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246';
const publicAccount =  PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);

const pageSize = 10; // Page size between 10 and 100, otherwise 10

accountHttp
    .transactions(publicAccount, new QueryParams(pageSize))
    .subscribe(transactions => console.log(transactions), err => console.error(err));
        final AccountHttp accountHttp = new AccountHttp("http://localhost:3000");

        // Replace with public key
        final String publicKey = "";

        final PublicAccount publicAccount = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);

        // Page size between 10 and 100, otherwise 10
        int pageSize = 20;

        final List<Transaction> transactions = accountHttp.transactions(publicAccount, new QueryParams(pageSize, null)).toFuture().get();

        System.out.print(transactions);
const accountHttp = new AccountHttp('http://localhost:3000');

const publicKey = '7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246';
const publicAccount =  PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST);

const pageSize = 10; // Page size between 10 and 100, otherwise 10

accountHttp
    .transactions(publicAccount, new QueryParams(pageSize))
    .subscribe(transactions => console.log(transactions), err => console.error(err));
nem2-cli account transactions --publickey 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246 --numtransactions 10

Note

By default, the SDK provides up to 10 transactions. The page size can be increased up to 100 transactions.

To get more than 100 transactions, you will have to make further requests. For each additional call, add to the QueryParams the optional parameter transactionId with the latest transaction identifier known returned by the previous request.

new QueryParams(pageSize, transactions[transactions.length - 1].transactionInfo.id))

You can also get filtered the transactions received (incoming) from the ones sent (outgoing) checking the complete accountHttp reference.