-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit with README, get_eth_balance, and get_eth_code as proof …
…of concept functions
- Loading branch information
1 parent
77f5724
commit cbb93a0
Showing
32 changed files
with
1,618 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
^onchainR\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ | ||
^README\.Rmd$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.Rdata | ||
.httr-oauth | ||
.DS_Store | ||
.quarto | ||
/dev/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Package: onchainR | ||
Title: Get blockchain data using R and tidyverse | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person("Brandon", "Kramer", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "0000-0002-3233-5310")) | ||
Maintainer: Brandon Kramer <[email protected]> | ||
Description: The onchainR package helps users get blockchain (or web3) data using JSON-RPC APIs and subgraphs in R. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
URL: https://github.com/brandonleekramer/onchainR/ | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.3 | ||
Imports: | ||
magrittr, | ||
stringr, | ||
httr2, | ||
onchainR | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,2 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Brandon Kramer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
YEAR: 2024 | ||
COPYRIGHT HOLDER: tidyweb3 authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2024 tidyweb3 authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(eth_get_balance) | ||
export(eth_get_code) | ||
importFrom(magrittr,"%>%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#' Get an Ethereum wallet balance | ||
#' | ||
#' @param wallet_address An Ethereum wallet balance (ENS domains not supported). | ||
#' @param provider_url The URL of a JSON-RPC provider such as Pocket Network, Infura, or Alchemy. | ||
#' @param api_key The API key of the JSON-RPC provider. | ||
#' | ||
#' @return A numeric value of an Ethereum balance. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' vitalik_eth = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" | ||
#' my_provider_url = "https://eth-mainnet.rpc.grove.city/v1/" | ||
#' my_api_key = "fadc98f89" | ||
#' | ||
#' eth_get_balance(vitalik_eth, my_provider_url, my_api_key) | ||
#' | ||
eth_get_balance = function(wallet_address, provider_url, api_key){ | ||
request_output = httr2::request(stringr::str_c(provider_url, api_key)) %>% | ||
httr2::req_headers('accept' = "application/json", | ||
'content-type' = "application/json") %>% | ||
httr2::req_body_raw( | ||
stringr::str_c('{"id": 1,"jsonrpc": "2.0", | ||
"method": "eth_getBalance", | ||
"params": ["',wallet_address,'", "latest"]}')) %>% | ||
httr2::req_perform() %>% | ||
httr2::resp_body_json() | ||
request_output = as.numeric(request_output$result)/(10^18) | ||
request_output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' Fill in later | ||
#' | ||
#' @param wallet_address An Ethereum wallet balance (ENS domains not supported). | ||
#' @param provider_url The URL of a JSON-RPC provider such as Pocket Network, Infura, or Alchemy. | ||
#' @param api_key The API key of the JSON-RPC provider. | ||
#' | ||
#' @return A numeric value of an Ethereum balance. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' vitalik_eth = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" | ||
#' my_provider_url = "https://eth-mainnet.rpc.grove.city/v1/" | ||
#' my_api_key = "fadc98f89" | ||
#' | ||
#' eth_get_code(vitalik_eth, my_provider_url, my_api_key) | ||
#' | ||
eth_get_code = function(wallet_address, provider_url, api_key){ | ||
request_output = httr2::request(stringr::str_c(provider_url, api_key)) %>% | ||
httr2::req_headers('accept' = "application/json", | ||
'content-type' = "application/json") %>% | ||
httr2::req_body_raw(stringr::str_c('{"id": 1, | ||
"jsonrpc": "2.0", "method": "eth_getCode", | ||
"params": ["',wallet_address,'", "latest"]}')) %>% | ||
httr2::req_perform() %>% | ||
httr2::resp_body_json() | ||
request_output$result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#' Pipe operator | ||
#' | ||
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. | ||
#' | ||
#' @name %>% | ||
#' @rdname pipe | ||
#' @keywords internal | ||
#' @export | ||
#' @importFrom magrittr %>% | ||
#' @usage lhs \%>\% rhs | ||
#' @param lhs A value or the magrittr placeholder. | ||
#' @param rhs A function call using the magrittr semantics. | ||
#' @return The result of calling `rhs(lhs)`. | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
output: github_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-" | ||
) | ||
source("~/Documents/git/secrets.R") | ||
``` | ||
|
||
# onchainR <br><img src="man/figures/onchainR.png" align="right" height="210" /> | ||
|
||
<!-- badges: start | ||
[](https://github.com/tidyverse/ggplot2/actions/workflows/R-CMD-check.yaml) | ||
[](https://app.codecov.io/gh/brandonleekramer/tidyweb3?branch=main) | ||
[](https://cran.r-project.org/package=ggplot2) | ||
badges: end --> | ||
|
||
## Overview | ||
|
||
onchainR is a package for accessing blockchain and web3 data in R | ||
|
||
**Authors:** [Brandon Kramer](https://www.brandonleekramer.com/) | | ||
**License:** [MIT](https://opensource.org/licenses/MIT)<br/> | ||
|
||
## Installation | ||
|
||
You can install the development version of onchainR from [GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("brandonleekramer/onchainR") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
```{r example} | ||
library(tidyweb3) | ||
vitalik_eth = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" | ||
my_prc_provider = "https://eth-mainnet.rpc.grove.city/v1/" | ||
my_api_key = grove_api_key | ||
eth_get_balance(vitalik_eth, my_prc_provider, my_api_key) | ||
``` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
# onchainR <br><img src="man/figures/onchainR.png" align="right" height="210" /> | ||
|
||
<!-- badges: start | ||
[](https://github.com/tidyverse/ggplot2/actions/workflows/R-CMD-check.yaml) | ||
[](https://app.codecov.io/gh/brandonleekramer/tidyweb3?branch=main) | ||
[](https://cran.r-project.org/package=ggplot2) | ||
badges: end --> | ||
|
||
## Overview | ||
|
||
onchainR is a package for accessing blockchain and web3 data in R | ||
|
||
**Authors:** [Brandon Kramer](https://www.brandonleekramer.com/) \| | ||
**License:** [MIT](https://opensource.org/licenses/MIT)<br/> | ||
|
||
## Installation | ||
|
||
You can install the development version of onchainR from | ||
[GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("brandonleekramer/onchainR") | ||
``` | ||
|
||
## Example | ||
|
||
This is a basic example which shows you how to solve a common problem: | ||
|
||
``` r | ||
library(tidyweb3) | ||
|
||
vitalik_eth = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" | ||
my_prc_provider = "https://eth-mainnet.rpc.grove.city/v1/" | ||
my_api_key = grove_api_key | ||
|
||
eth_get_balance(vitalik_eth, my_prc_provider, my_api_key) | ||
#> [1] 1085.514 | ||
``` |
Oops, something went wrong.