Code Monkey home page Code Monkey logo

ethr's Introduction

'ethr' - An Ethereum Package for R

Description

The 'ethr' R package is an interface for accessing Ethereum blockchain data in R, querying the Ethereum Blockchain via the JSON-RPC API.

ethr provides several convenience and helper functions, such as:

  • Handling of hexadecimal conversion
  • Access block data
  • Access transaction data/transaction receipts
  • Bulk download management

Installation

The package will be submitted to CRAN soon, until then you can install it from Github using devtools:

# install.packages("devtools")
devtools::install_github("BSDStudios/ethr")

Setup

The package connects to either a Geth or Parity client running on a full Ethereum node via the JSON-RPC interface https://github.com/ethereum/wiki/wiki/JSON-RPC.

Please enable the following flags for Geth and Parity respectively to ensure that they can access the client.

  • Geth: --rpc --rpccorsdomain localhost
  • Parity: --jsonrpc-cors '*' --geth - not connecting in latest build, we're investigating.

Base Functions

These base functions are direct implementations of the available JSON-RPC methods detailed here, https://github.com/ethereum/wiki/wiki/JSON-RPC and replicate their functionality as much as possible.

  • eth_coinbase - Returns the client coinbase address.
  • eth_gasPrice - Returns the current price per gas in wei.
  • eth_accounts - Returns a list of addresses owned by client.
  • eth_blockNumber - Returns the number of most recent block.
  • eth_getBalance - Returns the balance of the account of given address.
  • eth_getStorageAt - Returns the value from a storage position at a given address.
  • eth_getTransactionCount - Returns the number of transactions sent from an address at given block number.
  • eth_gethBlockTransactionCountByHash - Returns the number of transactions in a block, given the block hash.
  • eth_getBlockTransactionCountByNumber - Returns the number of transactions in a block the given block number.
  • eth_getCode - Returns code at a given address.
  • eth_getBlockByHash - Returns information about a block from a hash.
  • eth_getBlockByNumber - Returns information about a block from the block number.
  • eth_getTransactionByHash - Returns the information about a transaction requested by transaction hash.
  • eth_getTransactionByBlockHashAndIndex - Returns information about a transaction by block hash and transaction index position.
  • eth_getTransactionByBlockNumberAndIndex - Returns information about a transaction by block number and transaction index position.
  • eth_getTransactionReceipt - Returns the receipt of a transaction by transaction hash.

Helper functions

These functions use the base function, queering the blockchain, but make it easier for the user to download larger chunks of data and to have more control over where those chunks are taken from.

  • getBockTransations will return a data frame of the transactions for either a given number of blocks or a specified range of blocks.

  • getBlockHeaders will return just the block header data for a given number of blocks or specified range of blocks.getBlockHeaders will return just the block header data for a given number of blocks or specified range of blocks.

  • bulkBlockDownload.R breaks a large block range up and manages the download size. All downloaded blocks will be stored in a ethr_blocks folder in the data_dir.

  • getBlockRange - Returns the minimum and maximum blocks that are currently downloaded for the analysis table. Note: this does not check for continuity, only returns min and max vales.

ethr's People

Contributors

kateharris142 avatar tinmice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethr's Issues

Changes to dev (for parity?) seem to break geth connection

So after some more testing with geth it seems that your new approach to handling the json creation seems to break geth connectivity. When debugging, the json includes the followin error:
{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"invalid argument 1: json: cannot unmarshal string into Go value of type bool"}}
Is that to be expected or did I give it the wrong input? It was my impression that the code converts any True/TRUE to true and thus should work...?

NULL return

As I do not currently have a working local node, I tested with my test account of INFURA, which should have the same API as geth. I can set the rpc_adress correctly, but no matter which function I try, I always get 'NULL' as a return. This could be because of some incompatibility, but in case not, is there some way to debug?
F.e. when I tried eth_getBlockByNumber it requires also the argument 'full_list' but this is not in the json_rpc version, so what is it for/what to put there?
In a similar vein, do you plan to add more convenience functions in the future? As an example the JS api has things like getTransactionsByAccount or similar helpful things.
(sorry for mixing these things, I hope it is okay for now, some of it might be due to my R ignorance)

package installs (probably correctly) but gives error

When installing, I got an error but i seemed to install fine. (package(ethr) worked without problem)
The output from installation was:

> devtools::install_github("BSDStudios/ethr")
Downloading GitHub repo BSDStudios/ethr@master
from URL https://api.github.com/repos/BSDStudios/ethr/zipball/master
Installing ethr
"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" --no-site-file --no-environ --no-save  \
  --no-restore --quiet CMD INSTALL  \
  "C:/Users/<User>/AppData/Local/Temp/Rtmp0qFgN7/devtools2bb024ee5c6a/BSDStudios-ethr-875ad25"  \
  --library="C:/Program Files/R/R-3.3.2/library" --install-tests 

The system cannot find the path specified.
* installing *source* package 'ethr' ...
** R
** data
*** moving datasets to lazyload DB
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (ethr)
Error: Command failed (1)

Is this anything to worry about or to be expected?

Minor typos

Nice. Hope this is the right place for a few suggestions.

README.Rmd and README.md

change end_block=blocks[1] to end_block=blocks[2]
remove line return and spaces between 50000, and parallel

README.Rmd:Line120: BulkDownload <- bulkBlockDownload(start_block=blocks[1], end_block=blocks[1], data_dir, chunk_size = 50000,
                              parallel = TRUE, cores = 3)

change reciept to receipt
README.Rmd:Line 138: reciept <- eth_getTransactionReceipt(SingleTrans)
README.Rmd:Line 139: reciept
README.Rmd:Line 143: hexDec(reciept$gasUsed)

change $blhash to $blHash
README.Rmd:Line 153: blockHash <- transactions[49,]$blhash

nodesPlot.Rd
change transaction to transactions
nodesPlot.Rd:line 26: nodesPlot(transaction,degree_thres=50,save_plot=TRUE)

bulkBlockDownload.R - ethr_blocks

Requires an existing ethr_blocks directory in the data_dir otherwise throws this error.

> BulkDownload <- bulkBlockDownload(start_block=blocks[1], end_block=blocks[2], data_dir="~/Documents/r/ethr/1bulk/", chunk_size=50000, parallel=TRUE, cores=3)
Progress disabled when using parallel plyr
 Hide Traceback

 Rerun with Debug
 Error in gzfile(file, "wb") : cannot open the connection 
3 gzfile(file, "wb") 
2 save(block_chunk, file = paste0(data_dir, "ethr_blocks/", st, 
    "-", en, ".rda")) at bulkBlockDownload.R#33
1 bulkBlockDownload(start_block = blocks[1], end_block = blocks[2], 
    data_dir = "~/Documents/r/ethr/1bulk/", chunk_size = 50000, 
    parallel = TRUE, cores = 3) 
In addition: Warning messages:
1: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’

2: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’

3: In gzfile(file, "wb") :
  cannot open compressed file '/Users/markthomas/Documents/r/ethr/1bulk/ethr_blocks/1246788-1246807.rda', probable reason 'No such file or directory'

Error on GetBlockTransactions

  |                                                                           |   0%
Error in data.frame(blNumber = as.numeric(hexDec(block$number)), blTimestamp = as.POSIXct(as.numeric(hexDec(block$timestamp)),  : 
  arguments imply differing number of rows: 1, 0

When testing things, I got above error message. This is while connected to a local geth node, and other things such as eth_blockNumber work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.