Individual transactions

The are several functions in the tronr package that allow one to obtain information on the TRON blockchain transactions. One of the key functions is get_tx_info_by_id(), which returns a transaction’s attributes based on its ID (in the form of a nested tibble). Such IDs can be obtained using several other tronr functions, e.g. get_block_info(), get_blocks_for_time_range(), get_tx_for_time_range() (see below), etc. Here is an example:

require(tronr)
require(dplyr)
require(tidyr)

# Get transactions of the latest block:
latest_block <- get_block_info(latest = TRUE)

# Pick an example transaction:
tx_id <- latest_block$tx[[1]]$tx_id[1]
tx_id
#> [1] "065c60de666da397f71e4fdb5000cef98d7a55703c12a30c0862f0351de62c8c"

# Retrieve transaction attributes (see ?get_tx_info_by_id
# for their definitions):
r1 <- get_tx_info_by_id(tx_id = tx_id, add_contract_data = FALSE)
glimpse(r1)
#> Rows: 1
#> Columns: 19
#> $ request_time             <dttm> 2021-07-12 22:05:21
#> $ tx_id                    <chr> "065c60de666da397f71e4fdb5000cef98d7a55703c1…
#> $ block_number             <chr> "31884296"
#> $ timestamp                <dttm> 2021-07-12 22:04:12
#> $ contract_result          <chr> "SUCCESS"
#> $ confirmed                <lgl> TRUE
#> $ confirmations_count      <int> 23
#> $ sr_confirm_list          <list> [<tbl_df[19 x 3]>]
#> $ contract_type            <chr> "TransferAssetContract"
#> $ from_address             <chr> "TS97iToX537ZrrsCjDe2DX6b7ExhSJEJdU"
#> $ to_address               <chr> "THausPfXerWALeGoCaJ2kjuHBvAjDnCHUn"
#> $ is_contract_from_address <lgl> FALSE
#> $ is_contract_to_address   <lgl> FALSE
#> $ costs                    <list> [<tbl_df[1 x 9]>]
#> $ trx_transfer             <dbl> 0
#> $ trc10_transfer           <list> [<tbl_df[1 x 5]>]
#> $ trc20_transfer           <lgl> NA
#> $ internal_tx              <lgl> NA
#> $ info                     <lgl> NA

If the add_contact_data argument is set to TRUE, the resultant tibble will also have a column named contract_data. This column will contain a list with raw data generated by the contract that performed the transaction of interest. The actual content of that list will depend on the nature of each transaction and the respective contract:

r2 <- get_tx_info_by_id(tx_id = tx_id, add_contract_data = TRUE)
glimpse(r2)
#> Rows: 1
#> Columns: 20
#> $ request_time             <dttm> 2021-07-12 22:05:21
#> $ tx_id                    <chr> "065c60de666da397f71e4fdb5000cef98d7a55703c1…
#> $ block_number             <chr> "31884296"
#> $ timestamp                <dttm> 2021-07-12 22:04:12
#> $ contract_result          <chr> "SUCCESS"
#> $ confirmed                <lgl> TRUE
#> $ confirmations_count      <int> 23
#> $ sr_confirm_list          <list> [<tbl_df[19 x 3]>]
#> $ contract_type            <chr> "TransferAssetContract"
#> $ from_address             <chr> "TS97iToX537ZrrsCjDe2DX6b7ExhSJEJdU"
#> $ to_address               <chr> "THausPfXerWALeGoCaJ2kjuHBvAjDnCHUn"
#> $ is_contract_from_address <lgl> FALSE
#> $ is_contract_to_address   <lgl> FALSE
#> $ costs                    <list> [<tbl_df[1 x 9]>]
#> $ trx_transfer             <dbl> 0
#> $ trc10_transfer           <list> [<tbl_df[1 x 5]>]
#> $ trc20_transfer           <lgl> NA
#> $ internal_tx              <lgl> NA
#> $ info                     <lgl> NA
#> $ contract_data            <list> [82700, "1004230", "TS97iToX537ZrrsCjDe2DX6b7…

r2$contract_data[[1]]
#> $amount
#> [1] 82700
#> 
#> $asset_name
#> [1] "1004230"
#> 
#> $owner_address
#> [1] "TS97iToX537ZrrsCjDe2DX6b7ExhSJEJdU"
#> 
#> $to_address
#> [1] "THausPfXerWALeGoCaJ2kjuHBvAjDnCHUn"
#> 
#> $tokenInfo
#> $tokenInfo$tokenId
#> [1] "1004230"
#> 
#> $tokenInfo$tokenAbbr
#> [1] "ADG"
#> 
#> $tokenInfo$tokenName
#> [1] "ADG"
#> 
#> $tokenInfo$tokenDecimal
#> [1] 2
#> 
#> $tokenInfo$tokenCanShow
#> [1] 3
#> 
#> $tokenInfo$tokenType
#> [1] "trc10"
#> 
#> $tokenInfo$tokenLogo
#> [1] "https://coin.top/production/upload/logo/1004230.png?t=1625502558192"
#> 
#> $tokenInfo$tokenLevel
#> [1] "4"
#> 
#> $tokenInfo$vip
#> [1] FALSE

Notice that all token amounts in the tibbles returned by get_tx_info_by_id() (see columns trx_transfer, trc10_transfer, trc20_transfer, and internal_tx) are expressed using the whole numbers and the decimal parts. However, if add_contract_data = TRUE, the returned raw contract data will show token amounts “as is”, i.e. expressed using the machine-level precision. See ?apply_decimal for details.

Transactions that took place within a time range

To retrieve a list of transactions and their attributes for a certain period of time, one can use the get_tx_for_time_range() function. In comparison to get_tx_info_by_id(), this function has two additional arguments that define the time range of interest - min_timestamp and max_timestamp. Both of these arguments expect Unix timestamps (including milliseconds):

tx_df <- get_tx_for_time_range(min_timestamp = "1577836800000",
                               max_timestamp = "1577836803000")

glimpse(tx_df)
#> Rows: 41
#> Columns: 20
#> $ request_time             <dttm> 2021-07-12 22:05:22, 2021-07-12 22:05:22, 20…
#> $ tx_id                    <chr> "5f131118e7e24725906a72f4327dbaaa09d988e24c76…
#> $ block_number             <chr> "15860581", "15860581", "15860581", "15860581…
#> $ timestamp                <dttm> 2020-01-01, 2020-01-01, 2020-01-01, 2020-01-…
#> $ contract_result          <chr> "SUCCESS", "SUCCESS", "SUCCESS", "SUCCESS", "…
#> $ confirmed                <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRU…
#> $ confirmations_count      <int> 16023738, 16023738, 16023738, 16023739, 16023…
#> $ sr_confirm_list          <list> [<tbl_df[19 x 3]>], [<tbl_df[19 x 3]>], [<tb…
#> $ contract_type            <chr> "TransferAssetContract", "TriggerSmartContrac…
#> $ from_address             <chr> "TXmUfpBfxRTdbZXhzuqEJKjsCaYnCkfcpV", "TUJRNW…
#> $ to_address               <chr> "TCQBxaNNQ2h1HbrWxWSg7Ae6gwwM3hLR54", "THEA3D…
#> $ is_contract_from_address <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
#> $ is_contract_to_address   <lgl> FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TR…
#> $ costs                    <list> [<tbl_df[1 x 8]>], [<tbl_df[1 x 8]>], [<tbl_…
#> $ trx_transfer             <dbl> 0.000, 200.000, 0.000, 82.983, 0.000, 0.000, …
#> $ trc10_transfer           <list> [<tbl_df[1 x 5]>], <NULL>, <NULL>, <NULL>, <…
#> $ trc20_transfer           <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ internal_tx              <list> <NULL>, <NULL>, [<tbl_df[12 x 12]>], <NULL>,…
#> $ info                     <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ contract_data            <list> [10000000, "1002830", "TXmUfpBfxRTdbZXhzuqEJ…

Account-specific transactions

Using the get_tx_info_by_account_address() function one can also retrieve transaction data for a specific account. Moreover, this can be done for a specific time range:

tx_df_acc <- get_tx_info_by_account_address(
  address = "TAUN6FwrnwwmaEqYcckffC7wYmbaS6cBiX",
  min_timestamp = "1577836800000",
  max_timestamp = "1577838600000"
  )

glimpse(tx_df_acc)
#> Rows: 18
#> Columns: 21
#> $ request_time             <dttm> 2021-07-12 22:05:38, 2021-07-12 22:05:38, 20…
#> $ address                  <chr> "TAUN6FwrnwwmaEqYcckffC7wYmbaS6cBiX", "TAUN6F…
#> $ tx_id                    <chr> "36ec18062510f22a469bfbb4af6c128c3e4874898435…
#> $ block_number             <chr> "15860591", "15860591", "15860591", "15860592…
#> $ timestamp                <dttm> 2020-01-01 00:00:36, 2020-01-01 00:00:36, 20…
#> $ contract_result          <chr> "SUCCESS", "SUCCESS", "SUCCESS", "SUCCESS", "…
#> $ confirmed                <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRU…
#> $ confirmations_count      <int> 16023734, 16023734, 16023734, 16023733, 16023…
#> $ sr_confirm_list          <list> [<tbl_df[19 x 3]>], [<tbl_df[19 x 3]>], [<tb…
#> $ contract_type            <chr> "TransferContract", "TransferContract", "Tran…
#> $ from_address             <chr> "TAUN6FwrnwwmaEqYcckffC7wYmbaS6cBiX", "TAUN6F…
#> $ to_address               <chr> "TDn2MK7n5SqVksSZtQDAhDEEumreywL42j", "TZ3QPt…
#> $ is_contract_from_address <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
#> $ is_contract_to_address   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
#> $ costs                    <list> [<tbl_df[1 x 8]>], [<tbl_df[1 x 8]>], [<tbl_…
#> $ trx_transfer             <dbl> 664296.00000, 925.55360, 99.15751, 153627.900…
#> $ trc10_transfer           <list> <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NUL…
#> $ trc20_transfer           <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ internal_tx              <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ info                     <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ contract_data            <list> [6.64296e+11, "TAUN6FwrnwwmaEqYcckffC7wYmbaS…

Please note: the number of transactions that take place on the TRON blockchain is very large, and thus users are advised to choose min_timestamp and max_timestamp wisely. If the requested time range is too large, the maximum number of transactions returned by the underlying Tronscan API will be capped at 10000, and the processing time may become prohibitively long. Chunking the time range of interest into smaller periods can help to avoid gaps in data in such cases. However, users would have to implement their own logic for that.