From the 1.0 documentation it looks as if you can't specify the block number when calling contract methods querying state, ie. myContract.myMethod().call({defaultBlock: 'latest' }). Is this a feature that will be added, since it was in web3 <1.0: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods (third parameter)
Hi,
Try the following call:
myContract.methods.methodName().call(transactionObject, blockNumber, callback)
The second parameter in the call function is the block number.
You can leave the transactionObject undefined
This can be closed... @dannystox 's solution is working.
If it does work can it be added to the documentation because there is no mention of it there
this is not working for me unfortunately.
Token.methods.balanceOf(account).call(null, block)
returns
Error: Couldn't decode uint256 from ABI: 0x
at SolidityTypeUInt.formatOutputUInt [as _outputFormatter] (/home/mjackson/microtick/node_modules/web3-eth-abi/src/formatters.js:174:15)
at SolidityTypeUInt.SolidityType.decode (/home/mjackson/microtick/node_modules/web3-eth-abi/src/type.js:252:17)
....
....
Ah - figured it out and thought I'd leave a note to remind others: the contract has to have been deployed for the historical block number you're calling it on :)
Also the web3 documention of the call method seems to be wrong. What's the purpose to give gas and gasPrice to a call method? I set the gasLimit to 1, it didn't change a thing.
Any updates on this? Seems to have not been updated yet.
@nivida:
Why is this closed?
It is not even fixed on the documentation of v1.2.0 (and I'm assuming that it was not fixed also on the documentation of v1.0, though this one seems to have been removed from the web completely).
Would also love to get a documentation on this functionality.
E.g. what to expect when I pass a still non-existing (future) block number or a -1?
+1
Friendly ping
Hi guys, there is a "defaultBlock" parameter in the contract call docs here: https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html#id30
Let me know if that is not what you are looking for. (sorry about the broken list formatting, that should be fixed with #3597)
@ryanio Thanks for responding,
Feel the documentation could be altered slightly to improve the clarity specifically, from, gasPrice and gas are bullet-pointed and indented from options making it clear that they are part of the options object. Additionally their field name ie "from" and their type are included and highlighted.
For the field "defaultBlock" the field name isn't included (I only knew it was called defaultBlock by reading this thread) meaning a developer may not know what that field name should be and the text isn't in bullet point form making it look like it isn't part of the object.
I tried a method call with defaultBlock block set and couldn't get it to work, here are the details of the function call
let web3 = new Web3(url)
const lendingPoolAbi = require('./ABIs/aave/lendingPool.json') // file found here https://github.com/aave/aave-protocol/blob/master/abi/LendingPool.json
const lendingPoolContractAddress = "0x398eC7346DcD622eDc5ae82352F02bE94C62d119"
const LendingPoolContract = new web3.eth.Contract(lendingPoolAbi, lendingPoolContractAddress)
const daiContractAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
LendingPoolContract.methods.getReserveData(daiContractAddress).call({defaultBlock: 10000000 }).then(console.log)
references
https://github.com/aave/aave-protocol/blob/master/abi/LendingPool.json
https://docs.aave.com/developers/developing-on-aave/the-protocol/lendingpool#getreservedata
it returned the data for the current block rather than block 10,000,000 would it be possible you to highlight where i've gone wrong and potentially provide an example of a working method call with the defaultBlock parameter so that future readers can use this as a reference.
Thanks for the help
For the field "defaultBlock" the field name isn't included (I only knew it was called defaultBlock by reading this thread) meaning a developer may not know what that field name should be and the text isn't in bullet point form making it look like it isn't part of the object.
@ciaranmcveigh5 yes sorry about that, we fixed it in #3597.
Your defaultBlock param is actually passing into the options field, you'll need to move it to the next param like so:
LendingPoolContract.methods.getReserveData(daiContractAddress).call({}, 10000000).then(console.log)
Most helpful comment
+1