Accuracy of data on ETH / EVM balance

Hi in the following query to look up the users token balances as of May 2020:

query MyQuery {
  EVM(dataset: combined, network: eth) {
    BalanceUpdates(
      where: {BalanceUpdate: {Address: {is: "0x010f7ec243bb5e7ed2b54cce49ca147e540e56fc"}}, Block: {Time: {till: "2020-05-01T22:16:59Z"}}}
    ) {
      Currency {
        Name
        SmartContract
        ProtocolName
        Symbol
      }
      balance: sum(of: BalanceUpdate_Amount, selectWhere: {gt: "100000", lt: "499000"})
    }
  }
}

You get the following token but this seems to contradict etherscan:

{
  "EVM": {
    "BalanceUpdates": [
      {
        "Currency": {
          "Name": "",
          "ProtocolName": "erc20",
          "SmartContract": "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a",
          "Symbol": ""
        },
        "balance": "466490"
      }
    ]
  }
}

https://etherscan.io/advanced-filter?fadd=0x010f7ec243bb5e7ed2b54cce49ca147e540e56fc&tadd=0x010f7ec243bb5e7ed2b54cce49ca147e540e56fc&txntype=2&tkn=0xe0b7927c4af23765cb51314a0e0521a9645f0e2a

Although this user had this token at several points, he trades it almost as soon as it hits his wallet each time. Whereas in bitquery it shows that his balance was 466,490.

Note the address or the date or token isn’t important here.
Its just a random example thats easy to see for data validation purposes.

What causes this issue and is there a fix for it?

Thank you in advance!

The last transaction on Etherscan was recorded on 2020-11-23 after which the balance became zero, however in the query the time considered is till 2020-05-01T22:16:59Z. Hence you might be getting the conflicting values. Change the following part to get the similiar results.

Block: {Time: {till: "2020-05-01T22:16:59Z"}}

Hi, I don’t fully understand your response.

What is the difference between your suggested edit of:

Block: {Time: {till: "2020-05-01T22:16:59Z"}}

Compared to what I had this seems the same?

I dont think thats the issue but i think I figured it out.
It has to do with the decimals of the balance.
When we use balance: sum(of: BalanceUpdate_Amount it should auto-correct for decimals but in some cases the tokens are not corrected properly?

In this case, the discrepancy is a 9 decimal token and if we look at the total remaining at 2020-05 we see that the real balance is: 0.00046649 but in the query result we get 466490.

Would this issue exist with all 9 decimal tokens so possibly one way to correct it is to find all the tokens with 9 decimals and adjust them? (possibly bitquery should adjust this at the data level?)

When i adjust my query above to also include decimals like so:

 Currency {
        Name
        SmartContract
        ProtocolName
        Symbol
        Decimals
      }

The output looks like so:

{
  "EVM": {
    "BalanceUpdates": [
      {
        "Currency": {
          "Decimals": 0,
          "Name": "",
          "ProtocolName": "erc20",
          "SmartContract": "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a",
          "Symbol": ""
        },
        "balance": "466490"
      }
    ]
  }
}

Note that it says decimals : 0 !! That explains it. it should be decimals 9 but it shows as decimals 0 which is probably the cause of the incorrect number.

Should each token always have a “value” for decimals? In this case i’ve checked other places and this token decimal is stated as 9 in a few places so i’m guessing this is a mistake?

Sorry for the long msg but i hope you can reply.

Thank you!

Hi, I wanted to say that you need to change this part

Block: {Time: {till: "2020-05-01T22:16:59Z"}}

with this one.

Block: {Time: {till: "2020-11-23T22:16:59Z"}}

After I ran this query

query MyQuery {
  EVM(dataset: combined, network: eth) {
    BalanceUpdates(
      where: {BalanceUpdate: {Address: {is: "0x010f7ec243bb5e7ed2b54cce49ca147e540e56fc"}}, Block: {Time: {till: "2020-11-23T22:16:59Z"}}}
    ) {
      Currency {
        Name
        SmartContract
        ProtocolName
        Symbol
        Decimals
      }
      balance: sum(of: BalanceUpdate_Amount, selectWhere: {gt: "100000", lt: "499000"})
    }
  }

I have recieved the following output.

{
  "EVM": {
    "BalanceUpdates": []
  }
}

To check the balance for the token in question I have ran the following query.

query MyQuery {
  EVM(dataset: combined, network: eth) {
    BalanceUpdates(
      where: {BalanceUpdate: {Address: {is: "0x010f7ec243bb5e7ed2b54cce49ca147e540e56fc"}}, Block: {Time: {till: "2020-11-23T22:16:59Z"}}, Currency: {SmartContract: {is: "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a"}}}
    ) {
      Currency {
        Name
        SmartContract
        ProtocolName
        Symbol
        Decimals
      }
      balance: sum(of: BalanceUpdate_Amount)
    }
  }
}

The output of the query is

{
  "EVM": {
    "BalanceUpdates": [
      {
        "Currency": {
          "Decimals": 0,
          "Name": "",
          "ProtocolName": "erc20",
          "SmartContract": "0xe0b7927c4af23765cb51314a0e0521a9645f0e2a",
          "Symbol": ""
        },
        "balance": "0"
      }
    ]
  }
}

I hope that answers your doubt.

Hi Sorry that doesn’t help because the purpose of my query is to find the balance of tokens in May 1, 2020 (in this example).
Your query asks for the balance in November 23, 2020 after the user has disposed of the token.
So it shows a balance of zero but that doesn’t address the issue of what the true balance was as of May 1, 2020.

The reason i’m asking is not about this specific wallet or this specific token or this specific date.
Its about trying to validate the data provided.

As of May 1, 2020 the wallet had 0.00046649 of that token and instead the result shows as 466490.
I’ve maybe correctly identified the issue as an incorrect "Decimals": 0 in the bitquery dataset so that when you do the query it thinks you have more than you have since they haven’t corrected for the right number of decimals. I don’t see this issue with 99% of the tokens but i do see it with some.

So my question is, why is this happening for certain tokens?

Whats the fix for this?
Are all "Decimals": 0 in the bitquery dataset in error due to it being unknown or are some truly 0?

Again, this is just an example case.
I’m trying to find a rule to get around this issue for multiple wallets over multiple time periods with multiple tokens.

Thank you