create account

Could not find method get_block_range by felixxx

View this thread on: hive.blogpeakd.comecency.com
· @felixxx ·
$17.33
Could not find method get_block_range
# Could not find method get_block_range

![image.png](https://files.peakd.com/file/peakd-hive/felixxx/23swgXW3rEcQj1rXf43NdvjKbPJTQhytji527QfMs2VBM2pQpzhULUVWdpYY4hQP2MCEA.png)

I am trying to build a tool for Hive, and as always, I run into problems.
Developing anything for Hive is a complete pain.
Here's a description of today's problem:

### block_api.get_block
Trying to isolate the problem, I come up with this:
```
<!DOCTYPE html>
<html>
<script>

var block_num = 50000000

fetch('https://anyx.io', {method: "POST", body: JSON.stringify({
    "id":1,
    "jsonrpc":"2.0",
    "method":"call",
    "params":[
        "block_api",
        "get_block",
        [block_num]
    ]
})})
.then(response => response.json())
.then(response =>{
    console.log(response)
});
    
</script>
</html>
```

...works fine:

![image.png](https://files.peakd.com/file/peakd-hive/felixxx/23t7578kUpYLh3JnTArpQUtNVRhr1g2EvpwfFvFJpNmAoF9gr7MjfH1gyptSf9DgkYxD7.png)

...but I want more than one block.

### block_api.get_block_range

Same code, different method:

```
<!DOCTYPE html>
<html>
<script>

var block_num = 50000000

fetch('https://anyx.io', {method: "POST", body: JSON.stringify({
    "id":1,
    "jsonrpc":"2.0",
    "method":"call",
    "params":[
        "block_api",
        "get_block_range",
        [block_num, 10]
    ]
})})
.then(response => response.json())
.then(response =>{
    console.log(response)
});
    
</script>
</html>
```

Result:

![image.png](https://files.peakd.com/file/peakd-hive/felixxx/Eo1vVZoXLtQuDVt9xTYVa6TeXgr9qBZucNcBdzpDp9w4RdR4pvyV7p52WBDy5ezTVHL.png)

>Could not find method get_block_range

# Could not find method get_block_range

_The journey begins._

I google ``get_block_range hive`` and am surprised to find good results, despite **Hive having the worst possible name for any project on the internet**.

### Hive Developer Portal

get_block: https://developers.hive.io/apidefinitions/#block_api.get_block
get_block_range: https://developers.hive.io/apidefinitions/#block_api.get_block_range

It uses different parameters, but the rest of the usage is identical.
According to that, I have done everything correctly. It just does not work.
So much for the Developer Portal.

...Further down in my google results I find a post by blocktrades, where he mentions ``get_block_range`` working on his nodes, 8 months ago.

https://hive.blog/hive-139531/@blocktrades/hive-api-node-performance-measurement

I try different nodes: 

>Could not find method get_block_range

I do more research and check through the hive-js code:

```
    {
      "api": "condenser_api",
      "method": "get_block_header",
      "params": ["block_num"]
    },
    {
      "api": "block_api",
      "method": "get_block",
      "params": ["block_num"]
    },

```
https://gitlab.syncad.com/hive/hive-js/-/blob/master/src/api/methods.js#L77

So ``get_block_header`` is a method of ``condenser_api``, not ``block_api``?
Now I am even more confused, as the Hive Developer Portal states differently:

https://developers.hive.io/apidefinitions/#block_api.get_block_header

For good measure, I try all APIs for the ``get_block_range`` method.

>Could not find method get_block_range

The only code example containing 'blocks' I can find is this:

https://developers.hive.io/tutorials-javascript/stream_blockchain_transactions.html

I get absolutely 0 use out of that tutorial and decide to write a post about how stupid this is.
Am I making a mistake somewhere? Am I the only person to ever use ``get_block_range``?

So I am searching beem to see how it works there:

``blocks = self.blockchain.rpc.get_block_range({'starting_block_num': starting_block_num,  "count": count}, api="block")['blocks']``

That looks familiar! So I check its usage here:

https://beem.readthedocs.io/en/latest/beem.block.html#beem.block.Blocks

```
Obtain a list of blocks

Parameters:	
name_list (list) – list of accounts to fetch
count (int) – (optional) maximum number of accounts to fetch per call, defaults to 100
blockchain_instance (Steem/Hive) – Steem() or Hive() instance to use when accessing a RPCcreator = Account(creator, blockchain_instance=self)
```

List of **accounts to fetch?** Why accounts?

If you are lucky enough to find commented code around Hive, the comment is either confusing or just wrong half of the time, it feels.

...at least it looks like beem is using the ``block_api``.

I am no wiser, as beem is using the rpc call pretty much the same as I do.

I am too frustrated to continue at this point.

That was my day developing a tool for Hive: No progress at all. Just hours of:

# Could not find method get_block_range
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 117 others
properties (23)
authorfelixxx
permlinkcould-not-find-method-getblockrange
categoryhive-dev
json_metadata"{"app":"peakd/2021.09.1","format":"markdown","description":"The pain of trying to build for Hive","tags":["hive-dev","dev"],"users":["blocktrades"],"image":["https://files.peakd.com/file/peakd-hive/felixxx/23swgXW3rEcQj1rXf43NdvjKbPJTQhytji527QfMs2VBM2pQpzhULUVWdpYY4hQP2MCEA.png","https://files.peakd.com/file/peakd-hive/felixxx/23t7578kUpYLh3JnTArpQUtNVRhr1g2EvpwfFvFJpNmAoF9gr7MjfH1gyptSf9DgkYxD7.png","https://files.peakd.com/file/peakd-hive/felixxx/Eo1vVZoXLtQuDVt9xTYVa6TeXgr9qBZucNcBdzpDp9w4RdR4pvyV7p52WBDy5ezTVHL.png"]}"
created2021-09-21 15:05:30
last_update2021-09-21 15:05:30
depth0
children13
last_payout2021-09-28 15:05:33
cashout_time1969-12-31 23:59:59
total_payout_value8.695 HBD
curator_payout_value8.639 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,635
author_reputation216,288,819,155,055
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,458,068
net_rshares20,772,127,919,355
author_curate_reward""
vote details (181)
@engrave ·
$0.56
[block_api.get_block_range](https://developers.hive.io/apidefinitions/#block_api.get_block_range)

Working example from documentation with curl:

`curl -s --data '{"jsonrpc":"2.0", "method":"block_api.get_block_range", "params":{"starting_block_num": 1, "count": 10}, "id":1}' https://api.hive.blog`

Working example with `fetch`:

```
<!DOCTYPE html>
<html>
<script>

var block_num = 50000000

fetch('https://anyx.io', {method: "POST", body: JSON.stringify({
    "id":1,
    "jsonrpc":"2.0",
    "method":"block_api.get_block_range",
    "params": {
        "starting_block_num": 1,
        "count": 10
    }
})})
.then(response => response.json())
.then(response =>{
    console.log(response)
});
    
</script>
</html>
```
👍  
👎  
properties (23)
authorengrave
permlinkre-felixxx-qzsl34
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-21 16:13:54
last_update2021-09-21 16:13:54
depth1
children1
last_payout2021-09-28 16:13:54
cashout_time1969-12-31 23:59:59
total_payout_value0.279 HBD
curator_payout_value0.279 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length725
author_reputation318,719,797,600,724
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,459,325
net_rshares669,535,782,719
author_curate_reward""
vote details (2)
@felixxx ·
Thank you very much
properties (22)
authorfelixxx
permlinkre-engrave-qzslkx
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-21 16:24:33
last_update2021-09-21 16:24:33
depth2
children0
last_payout2021-09-28 16:24:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length19
author_reputation216,288,819,155,055
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,459,504
net_rshares0
@gtg ·
You were using method:call which is pre-appbase style of calling stuff (should be deprecated in 2018 or so),
In link that you have provided: https://developers.hive.io/apidefinitions/#block_api.get_block_range
Examples are working one, take a look this:
```
curl -s --data '{"jsonrpc":"2.0", "method":"block_api.get_block_range", "params":{"starting_block_num": 1, "count": 3}, "id":42}' https://gtg.openhive.network
```
properties (22)
authorgtg
permlinkqzskw5
categoryhive-dev
json_metadata{"links":["https://developers.hive.io/apidefinitions/#block_api.get_block_range"],"app":"hiveblog/0.1"}
created2021-09-21 16:09:42
last_update2021-09-21 16:09:42
depth1
children5
last_payout2021-09-28 16:09:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length420
author_reputation461,806,510,899,194
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,459,239
net_rshares0
@felixxx ·
Believe it or not: I spent the whole morning looking at that example, trying to figure out how I could make that work for me.

Thanks for nothing.
properties (22)
authorfelixxx
permlinkre-gtg-qzsl8a
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-21 16:17:00
last_update2021-09-21 16:17:00
depth2
children4
last_payout2021-09-28 16:17:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length146
author_reputation216,288,819,155,055
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,459,373
net_rshares0
@engrave ·
For future reference - jsonrpc is basically a POST request with JSON body, so anytime you want to port those examples from `curl` to `fetch`, `axios`, or whatever request library you're using, just copy the body from example:

I.e change this:

```
curl -s --data '{"jsonrpc":"2.0", "method":"block_api.get_block_range", "params":{"starting_block_num": 1, "count": 3}, "id":42}' https://api.openhive.network
```

Into this:

```
<html>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
axios.post('https://api.openhive.network', {"jsonrpc":"2.0", "method":"block_api.get_block_range", "params":{"starting_block_num": 1, "count": 3}, "id":42}).then((result) => console.log(result.data))    
</script>
</html>
```

You can also use `hive-js` or `dhive` (although I'm not sure they support get_block_range request out-of-the-box).
👎  
properties (23)
authorengrave
permlinkre-felixxx-qzt13y
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-21 22:00:00
last_update2021-09-21 22:00:00
depth3
children3
last_payout2021-09-28 22:00:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length863
author_reputation318,719,797,600,724
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,465,402
net_rshares0
author_curate_reward""
vote details (1)
@hjrrodriguez ·
I see what was complicated friend but surely you will find a way to develop the program you want
properties (22)
authorhjrrodriguez
permlinkre-felixxx-2021921t16183971z
categoryhive-dev
json_metadata{"tags":["hive-dev","dev"],"app":"ecency/3.0.18-mobile","format":"markdown+html"}
created2021-09-21 20:18:27
last_update2021-09-21 20:18:27
depth1
children0
last_payout2021-09-28 20:18:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length96
author_reputation187,570,921,363,641
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,463,729
net_rshares0
@klye ·
$0.05
You best bet is to just emulate this function with looped iterating get block calls from the start and end block number of your range. Or what engrave said.
👍  
properties (23)
authorklye
permlinkre-felixxx-qzzl93
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-25 10:00:54
last_update2021-09-25 10:00:54
depth1
children2
last_payout2021-10-02 10:00:54
cashout_time1969-12-31 23:59:59
total_payout_value0.022 HBD
curator_payout_value0.023 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length156
author_reputation412,341,527,771,769
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,548,227
net_rshares55,892,049,615
author_curate_reward""
vote details (1)
@felixxx ·
Nah, that is messy + slow.

block_range works for me now. Want the snippet?
properties (22)
authorfelixxx
permlinkre-klye-qzzk4w
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-25 10:36:33
last_update2021-09-25 10:36:33
depth2
children0
last_payout2021-10-02 10:36:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length75
author_reputation216,288,819,155,055
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,548,730
net_rshares0
@felixxx ·
```
function rpcCall(node, method, params) {
    return new Promise(resolve =>{
        let bodyObj = {
            "id":1,
            "jsonrpc":"2.0",
            "method":method,
            "params":params
        }
        fetch(node, {method: 'POST', body: JSON.stringify(bodyObj)})
            .then(response => {
                resolve(response.json())
                return
        })
    })
}

function getBlocks(node, start, count) {
    return new Promise(resolve => {
        let method = "block_api.get_block_range";
        let params = {"starting_block_num": start, "count": count}
        rpcCall(node, method, params)
            .then(response => {
                resolve(response)
                return
        })
    })
}
```
properties (22)
authorfelixxx
permlinkre-klye-r01rky
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-26 15:12:36
last_update2021-09-26 15:12:36
depth2
children0
last_payout2021-10-03 15:12:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length750
author_reputation216,288,819,155,055
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,576,862
net_rshares0
@littlescribe ·
Try @klye 
properties (22)
authorlittlescribe
permlinkre-felixxx-qzz1x2
categoryhive-dev
json_metadata{"tags":["hive-dev"],"app":"peakd/2021.09.1"}
created2021-09-25 04:03:06
last_update2021-09-25 04:03:06
depth1
children0
last_payout2021-10-02 04:03:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10
author_reputation56,315,797,877,090
root_title"Could not find method get_block_range"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id106,543,574
net_rshares0