# Why anchor.js provide different results from querying lcd.terra.dev?

**URL:** <https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363>\
**Category:** General\
**Created:** [April 19, 2021, 3:09pm UTC](https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363 "2021-04-19T15:09:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ency](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@ency](https://forum.anchorprotocol.com/u/ency)\
**Post date:** [April 19, 2021, 3:09pm UTC](https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363/1 "2021-04-19T15:09:39Z")

</div>

I am about to do some lightweight widget for anchor protocol and I would like to use simple rest calls instead of using whole anchor.js  
However, if I query using anchor.js, I got correct result, eg. aquire pending rewards

```
anchorcli q staking reward-info terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd
{
  staker: 'terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd',
  reward_index: '0.283797841612686875',
  bond_amount: '20280038284',
  pending_reward: '1576571'
}

```

However, if I query contract using lcd.terra.dev, like  
curl -X GET `"https://lcd.terra.dev/wasm/contracts/terra1897an2xux840p9lrh6py3ryankc6mspw49xse3/store?query_msg=%7B%22staker_info%22%3A%20%7B%20%22staker%22%3A%20%22terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd%22%7D%7D" -H "accept: application/json"`

I got

`{"height":"2642567","result":{"staker":"terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd","reward_index":"0.283722242961145227","bond_amount":"20280038284","pending_reward":"43428"}}`

Which is weird as block number corresponds to current block number, but pending\_reward using lcd is wrong. Any suggestions?

---

<div class="post-metadata">

**Author:** ![ryanology045](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.anchorprotocol.com/ryanology045/32/14_2.png) [@ryanology045](https://forum.anchorprotocol.com/u/ryanology045)\
**Post date:** [April 23, 2021, 10:00am UTC](https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363/2 "2021-04-23T10:00:06Z")

</div>

@saad.najafi @kjessec Can you give this a look?

---

<div class="post-metadata">

**Author:** ![kjessec](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kjessec](https://forum.anchorprotocol.com/u/kjessec)\
**Post date:** [April 23, 2021, 3:11pm UTC](https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363/3 "2021-04-23T15:11:49Z")

</div>

The difference is there because your LCD query didn’t include `block_height` in your query. Specifying the optional parameter, `block_height`, will give you a simulated reward as of the block height, whereas if you omitted it’ll give you only the stored state.

[https://docs.anchorprotocol.com/smart-contracts/anchor-token/staking#stakerinfo](https://docs.anchorprotocol.com/smart-contracts/anchor-token/staking#stakerinfo)

Since staking rewards are given out in periods, the contract cannot give you the total amount of reward you have earned so far since the last period state change. When you specify the `block_height`, it’ll try to extrapolate how much you would’ve earned since the last state change using the current reward factor, giving you a better outlook of what the reward is actually like.

If you were to do the anchorcli command and lcd query using the same block height (i.e. curl -X GET “[https://lcd.terra.dev/wasm/contracts/terra1897an2xux840p9lrh6py3ryankc6mspw49xse3/store?query\_msg={“staker\_info”%3A%20{%20"staker"%3A%20"terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd"%2C"block\_height"%3A2694201}}](https://lcd.terra.dev/wasm/contracts/terra1897an2xux840p9lrh6py3ryankc6mspw49xse3/store?query_msg=%7B%22staker_info%22%3A%20%7B%20%22staker%22%3A%20%22terra1se7ml7wt7pqzjhajhw5ma9lnstcs429lmj0wzd%22%2C%22block_height%22%3A2694201%7D%7D)” -H “accept: application/json”) it’ll yield the same result.

Please note that the block height parameter can only be bigger than the latest known (=current) block height. Specifying a block height smaller than the current height will result in a negative Uint256 operation which will give you an error.

---

<div class="post-metadata">

**Author:** ![ency](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@ency](https://forum.anchorprotocol.com/u/ency)\
**Post date:** [April 25, 2021, 9:09am UTC](https://forum.anchorprotocol.com/t/why-anchor-js-provide-different-results-from-querying-lcd-terra-dev/363/4 "2021-04-25T09:09:35Z")

</div>

Thanks! That was it, I’ve never tried higher than current block number.
