vechain / vechain-sdk-js

The official JavaScript SDK for VeChain.
19 stars 6 forks source link

🐛 [BUG] - RPC `eth_getBlockByNumber` rejects numbers #1013

Closed ifavo closed 6 days ago

ifavo commented 6 days ago

Description

When calling eth_getBlockByNumber with a block number, it fails with:

The params should be [blockNumber: string (an hex number) | "latest" | "finalized", transactionDetailFlag: boolean]'

Block hashes or references work correctly.

Reproduction URL

No response

Reproduction steps

import { ThorClient, VeChainProvider } from "@vechain/sdk-network";

const thorClient = ThorClient.fromUrl("https://mainnet.vechain.org");
const provider = new VeChainProvider(thorClient);

// failing request
const byNumber = await provider.request({ method: "eth_getBlockByNumber", params: [0, false] });
console.log("Successfully called eth_getBlockByNumber", byNumber);

Screenshots

![DESCRIPTION](LINK.png)

Logs

No response

OS

No response

ifavo commented 6 days ago

I double checked the docs, while the original ethereum docs note that ist must be hex encoded, other providers like ankr support regular numbers. I only compared it to that instead of the docs.

I think I was too quick to open as bug, because now I think its not. Sorry!

For example ankr:

$ curl -XPOST "https://rpc.ankr.com/eth" -H "content-type: application/json" -d '
{
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": [0,false],
    "id": "1"
}
' | jq
{
  "jsonrpc": "2.0",
  "id": "1",
  "result": {
    "difficulty": "0x400000000",
    "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
    "gasLimit": "0x1388",
    "gasUsed": "0x0",
    "hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner": "0x0000000000000000000000000000000000000000",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "nonce": "0x0000000000000042",
    "number": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x21c",
    "stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
    "timestamp": "0x0",
    "totalDifficulty": "0x400000000",
    "transactions": [],
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "uncles": []
  }
}