xiaoyao1991 / presto-ethereum

Presto Ethereum Connector -- SQL on Ethereum
Apache License 2.0
470 stars 56 forks source link

Get account balance #39

Closed riyazlafir closed 6 years ago

riyazlafir commented 6 years ago

Hi , I need to know how can I get account balance of the given ethereum account with presto-ethereum ? what is the presto query for this ?

thanks.

xiaoyao1991 commented 6 years ago

There's a UDF get_balance(). You can call it like ordinary utility function in SQL. Example:

SELECT block_miner, get_balance(block_miner), count(*) AS num, count(*)/100000.0 AS PERCENT
FROM block
WHERE block_number<=100
GROUP BY block_miner
ORDER BY num DESC
LIMIT 15;

More details here: https://github.com/xiaoyao1991/presto-ethereum/blob/master/src/main/java/im/xiaoyao/presto/ethereum/udfs/EthereumUDFs.java#L75-L94

riyazlafir commented 6 years ago

Hi Xiaoyao , I'm getting this error "Query 20180507_052320_00005_xjvrh failed: line 1:21: Function get_balance not registered" .

xiaoyao1991 commented 6 years ago

@riyazlafir I'm sorry. It should be eth_getBalance()

riyazlafir commented 6 years ago

@xiaoyao1991 Thanks . eth_getBalance() method works fine but I didn't get any ether balance from my default account .

this is the query I tried : SELECT block_miner, eth_getBalance(block_miner), count(*) AS num, count(*)/100000.0 AS PERCENT FROM block WHERE block_number<=100 GROUP BY block_miner ORDER BY num DESC LIMIT 15;

and out put : Query 20180507_070040_00017_xjvrh failed: Cannot get block number:

I'm trying to query parity ropsten network .

Parity running command : parity --chain ropsten --jsonrpc-apis "eth,net,web3,personal" --jsonrpc-cors '*' --jsonrpc-interface 0.0.0.0 --jsonrpc-port 8545 --jsonrpc-hosts="all"

do you know why i'm getting this out put ? do I need to add or change anything ?

xiaoyao1991 commented 6 years ago

Most likely you are running a warp sync parity client right? In that case, parity is only keeping the latest few blocks on the disk. The early blocks(the current query is only looking at the very first 100 blocks) info cannot be retrieved.

You can try with a different range of blocks in the query. For example, you can change the block_number <= 100 to block_number > eth_blockNumber() - 100