When the input of an event are all indexed, go-ethereum's JSON-RPC will response with data '0x', it will throw an error cause by the following code
ABICoder.prototype.decodeParameters = function (outputs, bytes) {
if (!bytes || bytes === '0x' || bytes === '0X') {
throw new Error('Returned values aren\'t valid, did it run Out of Gas?');
}
//...
}
I found the following test code, I assume Line 82 should be 0x not empty string
I'd like to work on it.
Confirmed same with 1.0.0-beta.36, appears to be a regression from unaffected 1.0.0-beta.35
Just in case you're wondering, ganache in this case returns: 0x00 which works.
btw. i think this one is related: https://github.com/ethereum/web3.js/issues/1916
Any simple workaround for this? My contract event filters are now broken.
@conscott I didn't manage to prepare a PR fixing it since current develop branch is much different so I used patch-package to fix it locally and create git patch applied on every yarn install. A dirty solution, but it works 🤷♂️
Here's patch:
patch-package
# FIX FOR: https://github.com/ethereum/web3.js/issues/2065
--- a/node_modules/web3-eth-abi/src/index.js
+++ b/node_modules/web3-eth-abi/src/index.js
@@ -222,7 +222,7 @@ ABICoder.prototype.decodeParameter = function (type, bytes) {
* @return {Array} array of plain params
*/
ABICoder.prototype.decodeParameters = function (outputs, bytes) {
- if (!bytes || bytes === '0x' || bytes === '0X') {
+ if (!bytes) {
throw new Error('Returned values aren\'t valid, did it run Out of Gas?');
}
thanks @krzkaczor !
the behavior still occurs on 1.0.0-beta.37 even though is reported on the changelog to be fixed. how can I be of more help?
This is still not resolved in beta 37. I've monkey patched it for now, but it would be nice to get an official fix. Anything I can do to help, please let me know! @krzkaczor
@travisdmathis what is your patch?
I just did a test in beta 37, the test codes are:
const ethABI = require('web3-eth-abi')
const ABI = [{
type: 'string',
name: 'MyString',
indexed: true
}, {
type: 'bool',
name: 'IsTrue',
indexed: true
}, {
type: 'uint8',
name: 'myNumberWork',
indexed: true
}]
const data = '0x'
const topics = ['0xffdd000000000000000000000000000000000000000000000000000000000003', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000fd44']
console.log(ethABI.decodeLog(ABI, data, topics))
Seems the problem is solved, @travisdmathis @rmujica can you provide some cases that will produce the error? Otherwise, I will close this issue
Most helpful comment
I'd like to work on it.