All Projects → xiaoyao1991 → Presto Ethereum

xiaoyao1991 / Presto Ethereum

Licence: apache-2.0
Presto Ethereum Connector -- SQL on Ethereum

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Presto Ethereum

Disperse
React/Redux dApp (decentralized app) boilerplate using Ethereum's blockchain
Stars: ✭ 36 (-92%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
React Ethereum Dapp Example
A starter boilerplate for an Ethereum dapp using web3.js v1.0, truffle, react, and parity
Stars: ✭ 384 (-14.67%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
Aztec
Public repository for the AZTEC protocol
Stars: ✭ 483 (+7.33%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
Smart Contracts Example
Simple example of token market. Based on blockchain technology using Ethereum platform.
Stars: ✭ 37 (-91.78%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
Ether sql
A python library to push ethereum blockchain data into an sql database.
Stars: ✭ 41 (-90.89%)
Mutual labels:  blockchain, ethereum, sql
Blockapi
A general framework for blockchain analytics
Stars: ✭ 111 (-75.33%)
Mutual labels:  blockchain, ethereum, sql
Etherscan Ml
Python Data Science and Machine Learning Library for the Ethereum and ERC-20 Blockchain
Stars: ✭ 55 (-87.78%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
Eventeum
A resilient Ethereum event listener that bridges your smart contract events and backend microservices
Stars: ✭ 272 (-39.56%)
Mutual labels:  blockchain, ethereum, ethereum-blockchain
Pantheon
An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client
Stars: ✭ 383 (-14.89%)
Mutual labels:  blockchain, ethereum
Solidity Cheatsheet
Cheat sheet and best practices for solidity. Write smart contracts for Ethereum.
Stars: ✭ 384 (-14.67%)
Mutual labels:  blockchain, ethereum
Nimbus Eth1
Nimbus: an Ethereum 1.0 and 2.0 Client for Resource-Restricted Devices
Stars: ✭ 386 (-14.22%)
Mutual labels:  blockchain, ethereum
Unchained
My personal study of blockchain related technology.
Stars: ✭ 379 (-15.78%)
Mutual labels:  blockchain, ethereum
Ethereumkit
EthereumKit is a free, open-source Swift framework for easily interacting with the Ethereum.
Stars: ✭ 400 (-11.11%)
Mutual labels:  blockchain, ethereum
Walleth
free (libre) native Android Ethereum wallet
Stars: ✭ 432 (-4%)
Mutual labels:  ethereum, ethereum-blockchain
Trueblocks Core
The main repository for the TrueBlocks system
Stars: ✭ 372 (-17.33%)
Mutual labels:  blockchain, ethereum
Crypto Whale Watching App
Python Dash app that tracks whale activity in cryptocurrency markets.
Stars: ✭ 389 (-13.56%)
Mutual labels:  ethereum, ethereum-blockchain
Buidl
A browser-based IDE for creating, deploying, and sharing blockchain apps (DApps, or decentralized apps). Publish your first blockchain DApps in 5 minutes! Here is how: https://docs.secondstate.io/buidl-developer-tool/getting-started
Stars: ✭ 376 (-16.44%)
Mutual labels:  blockchain, ethereum
Iexec Sdk
CLI and JS library allowing developers to easily interact with the iExec stack
Stars: ✭ 387 (-14%)
Mutual labels:  blockchain, ethereum
Swarm
swarm docs
Stars: ✭ 403 (-10.44%)
Mutual labels:  blockchain, ethereum
Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (-6.67%)
Mutual labels:  blockchain, ethereum

Presto Ethereum Connector

Unleash the Power of Presto Interactive SQL Querying on Ethereum Blockchain

Introduction

Presto is a powerful interactive querying engine that enables running SQL queries on anything -- be it MySQL, HDFS, local file, Kafka -- as long as there exist a connector to the source.

This is a Presto connector to the Ethereum blockchain data. With this connector, one can get hands on with Ethereum blockchain analytics work without having to know how to play with the nitty gritty Javascript API.

Prerequisites

Have an Ethereum client that you can connect to. There are 2 options:

  1. Run Geth or Parity locally.
  2. Use Infura, a hosted Ethereum client in the cloud.

Note

Specify a block range where you can (e.g. WHERE block.block_number > x AND block.block_number < y, or WHERE transaction.tx_blocknumber > x AND transaction.tx_blocknumber < y, or WHERE erc20.erc20_blocknumber > x AND erc20.erc20_blocknumber < y). Block number is the default and only predicate that can push down to narrow down data scan range. Queries without block ranges will cause presto to retrieve blocks all the way from the first block, which takes forever.

Usage

  1. Install Presto. Follow the instructions on that page to create relevant config files.
    By the end of this step, your presto installation folder structure should look like:

    ├── bin
    ├── lib
    ├── etc
    │   ├── config.properties
    │   ├── jvm.config
    │   └── node.properties
    ├── plugin
    
  2. Install Presto CLI

  3. Clone this repo and run mvn clean package to build the plugin. You will find the built plugin in the target folder.

  4. Load the plugin to Presto
    a. Create the ethereum connector config inside of etc.
    $ mkdir -p etc/catalog && touch etc/catalog/ethereum.properties
    Paste the following to the ethereum.properties:

    connector.name=ethereum
    
    # You can connect through Ethereum HTTP JSON RPC endpoint
    # IMPORTANT - for local testing start geth with rpcport
    # geth --rpc --rpcaddr "127.0.0.1" --rpcport "8545"
    ethereum.jsonrpc=http://localhost:8545/
    
    
    # Or you can connect through IPC socket
    # ethereum.ipc=/path/to/ipc_socketfile
    
    # Or you can connect to Infura
    # ethereum.infura=https://mainnet.infura.io/<your_token>
    

    b. Copy and extract the built plugin to your presto plugin folder

    $ mkdir -p plugin/ethereum \
      && cp <path_to_this_repo>/target/presto-ethereum-*-plugin.tar.gz . \
      && tar xfz presto-ethereum-*-plugin.tar.gz -C plugin/ethereum --strip-components=1
    

    By the end of this step, your presto installation folder structure should look like:

    ├── bin
    ├── lib
    ├── etc
    │   ├── catalog
    │   │   └── ethereum.properties
    │   ├── config.properties
    │   ├── jvm.config
    │   └── node.properties
    ├── plugin
    │   ├── ethereum
    │   │   └── <some jars>
    
  5. There you go. You can now start the presto server, and query through presto-cli:

$ bin/launcher start
$ presto-cli --server localhost:8080 --catalog ethereum --schema default

Use Cases

Inspired by An Analysis of the First 100000 Blocks, the following SQL queries capture partially what was depicted in that post.

  • The first 50 block times (in seconds)
SELECT b.bn, (b.block_timestamp - a.block_timestamp) AS delta
FROM
    (SELECT block_number AS bn, block_timestamp
    FROM block
    WHERE block_number>=1 AND block_number<=50) AS a
JOIN
    (SELECT (block_number-1) AS bn, block_timestamp
    FROM block
    WHERE block_number>=2 AND block_number<=51) AS b
ON a.bn=b.bn
ORDER BY b.bn;
  • Average block time (every 200th block from genesis to block 10000)
WITH
X AS (SELECT b.bn, (b.block_timestamp - a.block_timestamp) AS delta
        FROM
            (SELECT block_number AS bn, block_timestamp
            FROM block
            WHERE block_number>=1 AND block_number<=10000) AS a
        JOIN
            (SELECT (block_number-1) AS bn, block_timestamp
            FROM block
            WHERE block_number>=2 AND block_number<=10001) AS b
        ON a.bn=b.bn
        ORDER BY b.bn)
SELECT min(bn) AS chunkStart, avg(delta)
FROM
    (SELECT ntile(10000/200) OVER (ORDER BY bn) AS chunk, * FROM X) AS T
GROUP BY chunk
ORDER BY chunkStart;
  • Biggest miners in first 100k blocks (address, blocks, %)
SELECT block_miner, count(*) AS num, count(*)/100000.0 AS PERCENT
FROM block
WHERE block_number<=100000
GROUP BY block_miner
ORDER BY num DESC
LIMIT 15;
  • ERC20 Token Movement in the last 100 blocks
SELECT erc20_token, SUM(erc20_value) FROM erc20
WHERE erc20_blocknumber >= 4147340 AND erc20_blocknumber<=4147350
GROUP BY erc20_token;
  • Describe the database structure
SHOW TABLES;
    Table
-------------
 block
 erc20
 transaction

DESCRIBE block;
Column                 | Type               | Extra | Comment
-----------------------------------------------------------
block_number           | bigint             |       |
block_hash             | varchar(66)        |       |
block_parenthash       | varchar(66)        |       |
block_nonce            | varchar(18)        |       |
block_sha3uncles       | varchar(66)        |       |
block_logsbloom        | varchar(514)       |       |
block_transactionsroot | varchar(66)        |       |
block_stateroot        | varchar(66)        |       |
block_miner            | varchar(42)        |       |
block_difficulty       | bigint             |       |
block_totaldifficulty  | bigint             |       |
block_size             | integer            |       |
block_extradata        | varchar            |       |
block_gaslimit         | double             |       |
block_gasused          | double             |       |
block_timestamp        | bigint             |       |
block_transactions     | array(varchar(66)) |       |
block_uncles           | array(varchar(66)) |       |


DESCRIBE transaction;

Column              |    Type     | Extra | Comment
--------------------------------------------------
tx_hash             | varchar(66) |       |
tx_nonce            | bigint      |       |
tx_blockhash        | varchar(66) |       |
tx_blocknumber      | bigint      |       |
tx_transactionindex | integer     |       |
tx_from             | varchar(42) |       |
tx_to               | varchar(42) |       |
tx_value            | double      |       |
tx_gas              | double      |       |
tx_gasprice         | double      |       |
tx_input            | varchar     |       |


DESCRIBE erc20;
      Column       |    Type     | Extra | Comment
-------------------+-------------+-------+---------
 erc20_token       | varchar     |       |
 erc20_from        | varchar(42) |       |
 erc20_to          | varchar(42) |       |
 erc20_value       | double      |       |
 erc20_txhash      | varchar(66) |       |
 erc20_blocknumber | bigint      |       |

Web3 Functions

In addition to the various built-in Presto functions, some web3 functions are ported so that they can be called inline with SQL statements directly. Currently, the supported web3 functions are

  1. fromWei
  2. toWei
  3. eth_gasPrice
  4. eth_blockNumber
  5. eth_getBalance
  6. eth_getTransactionCount

Troubleshooting

  • You must use python2. You will get invalid syntax errors if you use Python3.
-> bin/launcher start
  File "/your_path/presto-server-0.196/bin/launcher.py", line 38
    except OSError, e:
                  ^
SyntaxError: invalid syntax
  • Use Java 8 only. You might get the following errors if you use the wrong Java version.
Unrecognized VM option 'ExitOnOutOfMemoryError'
Did you mean 'OnOutOfMemoryError=<value>'?
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].