Skip to content

Commit

Permalink
first commit with README, get_eth_balance, and get_eth_code as proof …
Browse files Browse the repository at this point in the history
…of concept functions
  • Loading branch information
brandonleekramer committed Feb 24, 2024
1 parent 77f5724 commit cbb93a0
Show file tree
Hide file tree
Showing 32 changed files with 1,618 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^onchainR\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.Rproj.user
.Rhistory
.Rdata
.httr-oauth
.DS_Store
.quarto
/dev/
21 changes: 21 additions & 0 deletions DESCRIPTION
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
23 changes: 2 additions & 21 deletions LICENSE
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
21 changes: 21 additions & 0 deletions LICENSE.md
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.
6 changes: 6 additions & 0 deletions NAMESPACE
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,"%>%")
29 changes: 29 additions & 0 deletions R/eth_get_balance.R
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
}
27 changes: 27 additions & 0 deletions R/eth_get_code.R
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
}
14 changes: 14 additions & 0 deletions R/utils-pipe.R
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
54 changes: 54 additions & 0 deletions README.Rmd
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
[![R-CMD-check](https://github.com/brandonleekramer/onchainR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidyverse/ggplot2/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/brandonleekramer/onchainR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/brandonleekramer/tidyweb3?branch=main)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/onchainR)](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)
```




40 changes: 40 additions & 0 deletions README.md
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
[![R-CMD-check](https://github.com/brandonleekramer/onchainR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidyverse/ggplot2/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/brandonleekramer/onchainR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/brandonleekramer/tidyweb3?branch=main)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/onchainR)](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
```
Loading

0 comments on commit cbb93a0

Please sign in to comment.