We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
According to the documentation here: https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#defaultblock
defaultBlock can be set to string like 'latest' or Number, it gives the example below:
// set the default block web3.eth.defaultBlock = 231;
When you next make call you will get error:
invalid argument 1: json: cannot unmarshal number into Go value of type string
See code at bottom.
Problem is you must supply Hex String of Number, so the following will work:
const latestBlock = await web3.eth.getBlockNumber() web3.eth.defaultBlock = web3.utils.numberToHex( latestBlock - 1 )
So either, change documentation, or change something else I think.
const w3provider = 'wss://goerli.infura.io/ws/v3/<SECRETKEY>' const Web3 = require('web3') const web3 = new Web3( new Web3.providers.WebsocketProvider(w3provider) ) ; ( async () => { const latestBlock = await web3.eth.getBlockNumber() web3.eth.defaultBlock = latestBlock - 1 const accountBal = await web3.eth.getBalance( '0x1addbb6462cb45c91f0dd116c6480aa586de0a29' ) console.log(`(${accountBal})`) })()
The text was updated successfully, but these errors were encountered:
Thanks for opening this issue! I will add the missing conversion to a hex string asap.
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Expected behavior
According to the documentation here: https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#defaultblock
defaultBlock can be set to string like 'latest' or Number, it gives the example below:
// set the default block
web3.eth.defaultBlock = 231;
Actual behavior
When you next make call you will get error:
See code at bottom.
Problem is you must supply Hex String of Number, so the following will work:
So either, change documentation, or change something else I think.
js code to reproduce the behavior
The text was updated successfully, but these errors were encountered: