Reading transactions from an account

Get the list of transactions where an account is involved.

Prerequisites

Method #01: Using the SDK

  1. To get the latest confirmed transactions for a given account, open a new file, and copy the following code snippet.
// replace with account address
const rawAddress = 'TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4';
const address = Address.createFromRawAddress(rawAddress);
// replace with node endpoint
const nodeUrl = 'http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const accountHttp = repositoryFactory.createAccountRepository();
// Page size between 10 and 100
const pageSize = 10;
const queryParams = new QueryParams({pageSize});

accountHttp
    .getAccountTransactions(address, queryParams)
    .subscribe((transactions) => console.log(transactions),
        (err) => console.error(err));
// replace with account address
const rawAddress = 'TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
// replace with node endpoint
const nodeUrl = 'http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const accountHttp = repositoryFactory.createAccountRepository();
// Page size between 10 and 100
const pageSize = 10;
const queryParams = new symbol_sdk_1.QueryParams({ pageSize });
accountHttp
    .getAccountTransactions(address, queryParams)
    .subscribe((transactions) => console.log(transactions), (err) => console.error(err));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000")) {

            final AccountRepository accountRepository = repositoryFactory
                .createAccountRepository();
            final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
            // Replace with account address
            final String publicKey = "E59EF184A612D4C3C4D89B5950EB57262C69862B2F96E59C5043BF41765C482F";
            final PublicAccount publicAccount = PublicAccount
                .createFromPublicKey(publicKey, networkType);

            // Page size between 10 and 100
            Integer pageSize = 10;
            final TransactionSearchCriteria transactionSearchCriteria = new TransactionSearchCriteria();
            transactionSearchCriteria.pageSize(pageSize);

            final List<Transaction> transactions = accountRepository
                    .transactions(publicAccount, transactionSearchCriteria).toFuture().get();
            final JsonHelper helper = new JsonHelperJackson2();
            System.out.println(helper.prettyPrint(transactions));
        }

Note

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

2. To get more than 100 transactions, you will have to make further requests iteratively. 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))

Method #02: Using the CLI

Open a terminal window and run the following command to get the confirmed transactions involving an account.

symbol-cli account transactions --address TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4 --numtransactions 10