-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
114 lines (76 loc) · 5.81 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# tronr <a href='https://github.com/next-game-solutions/tronr/'><img src="man/figures/hex-tronr.png" align="right" height="150"/></a>
<!-- badges: start -->
[![R build status](https://github.com/next-game-solutions/tronr/actions/workflows/r.yml/badge.svg)](https://github.com/next-game-solutions/tronr/actions/workflows/r.yml)
[![Codecov test coverage](https://codecov.io/gh/next-game-solutions/tronr/branch/main/graph/badge.svg?token=Y9HOR0EO40)](https://codecov.io/gh/next-game-solutions/tronr)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
`tronr` is a toolbox to explore the [TRON blockchain](https://tron.network/index?lng=en). This R package allows one to collect data on the blockchain’s accounts, transactions, token transfers, and smart contract events. In addition, users can query the current and historical market status of [Tronix (TRX)](https://tron.network/trx?lng=en), the native currency of TRON.
## Installation
At the moment, `tronr` is only available on GitHub and can be installed with:
``` r
# install.packages("devtools")
devtools::install_github("next-game-solutions/tronr")
```
A [CRAN](https://cran.r-project.org/) version of the package is planned for release in the near future.
## Examples
Detailed examples of how to use `tronr` can be found in its [online documentation](https://next-game-solutions.github.io/tronr/). Provided below are just a few common queries:
```{r example, message=FALSE, fig.align='center', fig.width=10, fig.height=4.5}
library(tronr)
library(dplyr)
library(ggplot2)
# Current price of TRX expressed in USD, EUR and BTC (Bitcoin):
get_current_trx_price(vs_currencies = c("usd", "eur", "btc"))
# Querying the TRX market data for a historical period, and plotting the
# evolution of price:
(min_timestamp <- as.POSIXct("2020-01-01 00:00:00") %>% to_unix_timestamp())
(max_timestamp = as.POSIXct("2020-05-01 00:00:00") %>% to_unix_timestamp())
price_history <- get_trx_market_data_for_time_range(
vs_currency = "usd",
min_timestamp = min_timestamp,
max_timestamp = max_timestamp
)
glimpse(price_history)
price_history %>%
ggplot(aes(timestamp, price)) +
geom_line() +
theme_minimal()
# Information on the latest block on the chain:
get_block_info(latest = TRUE) %>%
glimpse()
# Current balance of an account:
get_account_balance("TQjaZ9FD473QBTdUzMLmSyoGB6Yz1CGpux") %>%
glimpse()
# TRC-10 asset transfers to / from an account within a time range:
get_trc10_transfers(
related_address = "TMaBqmMRekKZMQEq3u3QrJpGDwPYZZo87V",
min_timestamp = "1577837400000",
max_timestamp = "1577837430000"
) %>% glimpse()
```
## Things to keep in mind when using `tronr`
The design of this package is rather opinionated, which among other aspects means the following:
1. Under the hood, most of the transaction-related data are queried in `tronr` via a public API that powers the [Tronscan website](https://tronscan.org/). This has a few important implications:
- The [Tronscan API](https://github.com/tronscan/tronscan-frontend/blob/master/document/api.md "Tronscan API") is considerably slower than the [TronGrid API](https://www.trongrid.io/), which is the recommended tool for use cases that require a computationally efficient and robust mechanism to extract large amounts of data from the TRON blockchain. However, the Tronscan API was chosen due to the richer and more schema-consistent data it returns. As the TronGrid API matures, the decision on using the Tronscan API in `tronr` may be re-considered.
- Attempts to perform frequent and/or "heavy" queries from the same IP address using `tronr` may be treated by the Tronscan servers as [denial-of-service attacks](https://www.cloudflare.com/en-gb/learning/ddos/glossary/denial-of-service/) and lead to black-listing of that IP address. Users of `tronr` are thus kindly asked to be considerate and implement the respective safeguards in their code (e.g., breaking the queries into smaller chunks, with pauses in between).
- As a result of the previous two points, `tronr` is _not_ intended for the development of high-load analytical applications.
2. Many of the `tronr` functions return data in the form of [nested tibbles](https://tidyr.tidyverse.org/articles/nest.html) (see examples above). Arguably, this is a natural choice for such data, given their hierarchical structure. Nested tibbles were chosen also because they represent a “tidy” data format compatible with the [`tidyverse`](https://www.tidyverse.org/ "tidyverse") toolkit (in particular, the [`tidyr`](https://tidyr.tidyverse.org/ "tidyr") package). Admittedly, though, not all R users prefer working with the `tidyverse` tools and this makes `tronr` somewhat less accessible and attractive for such users.
## Getting help
If you encounter a clear bug, please file an issue with a minimal reproducible example on [GitHub](https://github.com/next-game-solutions/tronr/issues).
## License
This package is licensed to you under the terms of the MIT License.
The TRON logo ("red diamond") used in the `tronr` hexagon sticker is property of the [TRON Foundation](https://tron.network/). It originates from the official icon pack, which is available for download and free use at the Foundation's website.
Copyright (c) `r substr(as.Date(Sys.Date()), 1, 4)` [Next Game Solutions OÜ](http://nextgamesolutions.com)
---
Please note that this project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/1/0/0/code-of-conduct/). By participating in this project you agree to abide by its terms.