xDai and POA Forum

Querying Core POA network blockchain via RPC/GraphQL

I’m trying to pull data from POA Core blockchain for analytics (e.g. blocks mined and list of transactions from specific POA address) via RPC and it’s timing out even for a single page with an offset of 1 (i.e. asking for just one item).

Is this documented API supposed to work? https://blockscout.com/poa/core/api_docs? I assume blockscout.com doesn’t go through RPC, since it’s actually working?

What’s the recommended way for querying the blockchain from outside the blockchain?

Best, MM

FWIW I also didn’t have much success going the GraphQL route on top of POA Core.

Internal server errors and gateway timeouts suggest the API is disfunctional.

Both of the API should work. I can confirm the mentioned issues and will fix them next week. Sorry about that. While fixing the issues is in progress other Blockscout API endpoints are in operational state and also you can try TheGraph or Anyblock Analytics. They also provide support of POA chain

2 Likes

Hi MM,

this is Peter from Anyblock Analytics.
Here is some more detailed information:

You can create a free account here: https://account.anyblock.tools/auth/signup/
You’ll find the general documentation here: https://docs.anyblock.tools/en/latest/
We are providing the data in SQL and Elasticsearch. I suggest you try Elastic since it is much quicker.

I can only post two links, so I’ll send the other ones in the next post.

Best,
Peter

3 Likes

Hi MM,

This is the API documentation : https://apidocs.anyblock.tools/
And this is our POA Core blockexplorer: https://explorer.anyblock.tools/ethereum/poa/core/
We also have POA Sokol and xDAI.

If you have any questions or something doesn’t seem to work correctly you can contact me anytime.

Best,
Peter

2 Likes

@Micwebnet

Regarding “Get mined blocks” API endpoint. I fixed its performance. An example of a successful query with 1000 items per page:
https://blockscout.com/poa/core/api?module=account&action=getminedblocks&address=0xDC4765D9DAbF6c6c4908fE97E649Ef1F05Cb6252&page=1&offset=1000

Regarding of GraphQL address -> transactions query, I processed “Internal server error”. Now it returns handled error:

{
  "data": {
    "address": {
      "contractCode": null,
      "transactions": null
    }
  },
  "errors": [
    {
      "locations": [
        {
          "column": 3,
          "line": 3
        }
      ],
      "message": "You must either supply `:first` or `:last`",
      "path": [
        "address",
        "transactions"
      ]
    }
  ]
}

In order to get transactions per address you need to specify first or last, count params like this:

{address(hash: "0xF977814e90dA44bFA03b6295A0616a897441aceC") {
  contractCode,
  transactions(first: 10) {
    edges {
      node {
        toAddressHash
      }
    }
  }
}
}

Sokol and POA instances of Blockscout are patched with both fixes.

2 Likes

@viktorbaranov, thanks for fixing the API. I’ll try it again if I run into a dead-end with AnyBlock solution.

@PeterE, thanks for the info! What I’m trying to pull is every POA block reward for a specific mining key. AnyBlock solution looks very promising (I bet ES and even SQL can deal with filtered queries faster than querying Parity via JSON-RPC).

Since I’m on Power BI I first tried the SQL route, and it worked, though very slowly (low throttling limits). Even with 12h chunks it takes a couple of hours to pull txs sent to a specific payout address on POA Core blockchain. SQL route got me halfway. Pre-11/26/18 I can see mined block rewards by filtering tx table to miner’s payout wallet when POA Core still had a scheduled hourly transfer task from mining wallet to payout wallet, but after 11/26/18 it only includes tx/uncle fees, with rewards paid out directly to payout wallet and I can’t find where POA block rewards are being tracked in the blocks table. The blocks table doesn’t seem to be (well) documented, so I can’t make sense of most of its schema. Is there a doc to define blocks fields? My understanding is that the last tx in every block is the block signing (mining) reward transfer, but it’s not showing up in tx table, so must be incrementing wallet balance some other way.

Update: I now understand I need to query for internal transactions (contract messages that transfer value to payout wallet). Searched in calls table and I couldn’t see either mining or payout wallet address in to field.

Next I tried the ES route, since that should be faster. I installed the ES ODBC driver (https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-odbc-setup.html), but can’t seem to connect it to AnyBlocks. Do you have instructions on how to connect to ES via their ODBC driver?

Best, MM

Btw, I also tried going the REST API POST route and didn’t get any results filtering either to all txs from mining or all tx to payout wallet. When I run ETH/mainnet ES queries, I do get results, but not for POA/core ES queries:

Best, MM

Tried this with another address and GraphQL is timing out:

Getting

Best, MM

Hi @Micwebnet,

see this thread: Tracking mined rewards using BlockScout for examples on how to get balances and traces via the Anyblock Analytics ElasticSearch API.

As for the ODBC driver, we don’t support ElasticSearch SQL access at the moment, as the functionality is quite limited and we’re offering a native PostgreSQL Database anyways.

Getting the block rewards via SQL would look like this:

SELECT 
	"value", 
	"block_hash",
	"block_number",
	"timestamp"
FROM "trace"
WHERE "trace_type" = 'reward'
AND "to" = LOWER('0x1985293823D122F11AbFbB82fB245e345A0AC60d')
ORDER BY "timestamp" DESC
LIMIT 1000

The ElasticSearch performance is way better though. :wink:

1 Like

Thanks! The reason I was looking the SQL route is that I need to load this into Power BI and ES guides you to ODBC for that: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/sql-client-apps-powerbi.html.

My two options to try next are your PostgreSQL (PowerBI supports that) and maybe try to make sense of the ES responses treating it as regular REST API in Power BI (though I’d lose query folding). Will try and report back.

I was looking at the calls table for internal transactions representing rewards. Couldn’t find them there. How come these are in the trace table, but not showing up as calls? Shouldn’t every value transfer implemented by a smart contract show up as an internal tx call?

Update: I’ve confirmed that I can get to rewards to a payout wallet address from the trace table via Postgre SQL route in Power BI. Besides trace_type=reward, I’m also seeing trace_type=call on this to address, from the mining address, happening at 1h intervals. Are those tx fees and uncle fees transferred hourly that I also see in the tx table, or smth else? I didn’t expect to see proper blockchain ledger transfers tracked as calls.

Best, MM

1 Like

The Anyblock call index/table represents ABI-translated (regular) transactions, which is the equivalent of the event index for logs.

We will have the same for internal transactions hopefully soon, probably called internal_call.

Outgoing transactions from your validator usually are benign validator reports. Whenever another validator is late or sends unexpected data, your node will automatically send a report transaction to the validator-set contract. You should also be able to see these in your node logs Reported benign validator ... something

ALL transactions always result in at least one trace. For complex smart-contract interactions, it’s a complete call stack, but for a simple value transfer it’s just a single trace with the transferred volume. Therefore the trace/internal transaction table has information on everything that changed the blockchain state in some way.

Regarding the PostgreSQL database: There are indices on timestamp, block_number and from/to, so if you can limit your query, do so as early as possible, because the table is HUGE :wink: