Reading transactions from an account

Get the complete list of transactions involving an account.

Prerequisites

Method #01: Using the SDK

  1. Open a new file and define the account address.

// replace with account address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = Address.createFromRawAddress(rawAddress);
// replace with account address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
            // replace with signer public key
            NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
            PublicAccount signer = PublicAccount.createFromPublicKey(
                "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
                networkType);

2. Define a new TransactionHttp repository and the search criteria. In this example, we will retrieve all account-related transactions with at least one confirmation, but you could also query the unconfirmed and partial collections.

// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();

const searchCriteria = {
  group: TransactionGroup.Confirmed,
  address,
  pageNumber: 1,
  pageSize: 100,
};
transactionHttp.search(searchCriteria).subscribe(
  (page) => console.log(page.data),
  (err) => console.error(err),
);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
const searchCriteria = {
    group: symbol_sdk_1.TransactionGroup.Confirmed,
    address,
    pageNumber: 1,
    pageSize: 100,
};
transactionHttp.search(searchCriteria).subscribe((page) => console.log(page.data), (err) => console.error(err));
            final TransactionRepository transactionRepository = repositoryFactory
                .createTransactionRepository();

            TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(
                transactionRepository);

            Observable<Transaction> transactions = streamer
                .search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED)
                    .address(signer.getAddress()));

            System.out.println(transactions.toList().toFuture().get());

3. The API returns pages with up to 100 transactions. The page object contains meta information about the total amount of transactions and pages available.

To get more transactions, you will have to make further requests iteratively. For each extra call, increase the pageNumber by one unit.

const searchCriteria = {group: TransactionGroup.Confirmed, address, pageNumber: 2, pageSize: 100};

4. Since the transaction collection might grow while paginating, it’s advised to set the first transaction you want to start pagination. Set an offset value with the first transaction internal identifier.

const searchCriteria = {group: TransactionGroup.Confirmed, address, pageNumber: 2, pageSize: 100, id:85BBEA6CC462B244};

Method #02: Using the CLI

Open a terminal window and run the following command.

Replace TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I with the address you want to query.

symbol-cli transaction search --address TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I