Web3.js: call function bool value issue

Created on 22 Sep 2017  ·  13Comments  ·  Source: ChainSafe/web3.js

Lib version : "web3": "^1.0.0-beta.21"

contract.methods.challenge().call({
                        from: adminAddress
                    }, function (error, result) {
console.log(error)
}

Error: Couldn't decode bool from ABI: 0x
at SolidityTypeBool.formatOutputBool (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-abi/src/formatters.js:195:15)
at SolidityTypeBool.SolidityType.decode (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-abi/src/type.js:252:17)
at /Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-abi/src/index.js:327:49
at Array.forEach (native)
at ABICoder.decodeParameters (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-abi/src/index.js:326:13)
at Contract._decodeMethodReturn (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-contract/src/index.js:490:22)
at Method._parent._ethereumCall.call.method.outputFormatter (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-eth-contract/src/index.js:820:42)
at Method.formatOutput (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-core-method/src/index.js:179:54)
at sendTxCallback (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-core-method/src/index.js:446:33)
at /Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-core-requestmanager/src/index.js:144:9
at XMLHttpRequest.request.onreadystatechange (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/web3-providers-http/src/index.js:64:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage. (/Users/smartSense/Ronak Thacker/Node JS/WordwormBackend/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:91:20)

clarification needed

Most helpful comment

This happens when you are using wrong address for your smart contract.
Yes, I wish the web3 errors messages could be less misleading.

All 13 comments

Bool should not return 0x, it should be rather 0x00000000000...
Can you check which node youre using and whats coming across from the node?
E.g. you can use HTTPProvider and inspect the network traffic.

I was getting this same error. In my case the mistake was using .call() when I should've been using .send().

From the documentation:

.call():
Will call a “constant” method and execute its smart contract method in the EVM without sending any transaction. Note calling can not alter the smart contract state.

send():
Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.

Same error under beta.22. Here are my observations:

  • happens when I use a call to get the mapping field that has been just updated by a transaction in the same second.
  • If I keep re-issuing this call, it will finally get the correct result at the beginning of the next second. Here we are talking about natural seconds, not intervals.
  • reproducible on both geth and parity's dev chain
  • but it doesn't seem to be web3's problem as I can see that providers can only receive something like {"jsonrpc":"2.0","result":"0x","id":330} on a failure.

So, I guess it's probably an expected behaviour regarding synchronization or locking.

This happens when you are using wrong address for your smart contract.
Yes, I wish the web3 errors messages could be less misleading.

It seems downgrading worked for some people, but didn't test it yet.
https://ethereum.stackexchange.com/questions/26764/unhandled-rejection-error-couldnt-decode-uint256-from-abi

I've encountered this bug today, however I'm still trying to isolate it. Will update when possible.

I had this error, and it was absolutely weird. i somehow fixed it but using truffle(still uses web3 0.x version) to call my method instead of web3 1.0 beta 30, then my web3 call started working, is it because of EVM cache ? or web3 cache maybe ?
I figured out that it is not a cache problem, it is the fact that web3 can't really decode bool value (byte32 in my case) from 0x which is the value the truffle call returned to me.

This fix from the other issue thread worked for me:

For now, you can use -

web3.eth.call({
     to: address,
     data: contract.methods.balanceOf(address).encodeABI()
}).then(balance => {})

@rhlsthrm I'm trying that, it runs.. but I didn't expect this:

Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }

when calling a uint field on my contract. is bitField the value?

It sounds like you are not awaiting the Promise to resolve. What is your code syntax? If you use the then syntax like in my above example you should not get what you got.

@rhlsthrm

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
let c = new web3.eth.Contract(abi, keyaddress);

let on = c.methods.ownersNum().call();
        console.log(on);
  on.then(function(a,b) {
          console.log(a);
          console.log(b);
  });
node server.js
    at XMLHttpRequest._setReadyState (/root/scan/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/root/scan/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/root/scan/node_modules/xhr2/lib/xhr2.js:469:24)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:11979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11979) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:11979) UnhandledPromiseRejectionWarning: Error: Couldn't decode uint256 from ABI: 0x
    at SolidityTypeUInt.formatOutputUInt [as _outputFormatter] (/root/scan/node_modules/web3-eth-abi/src/formatters.js:174:15)
    at SolidityTypeUInt.SolidityType.decode (/root/scan/node_modules/web3-eth-abi/src/type.js:252:17)
    at /root/scan/node_modules/web3-eth-abi/src/index.js:327:49
    at Array.forEach (<anonymous>)
    at ABICoder.decodeParameters (/root/scan/node_modules/web3-eth-abi/src/index.js:326:13)
    at Contract._decodeMethodReturn (/root/scan/node_modules/web3-eth-contract/src/index.js:459:22)
    at Method.outputFormatter (/root/scan/node_modules/web3-eth-contract/src/index.js:812:46)
    at Method.formatOutput (/root/scan/node_modules/web3-core-method/src/index.js:163:54)
    at sendTxCallback (/root/scan/node_modules/web3-core-method/src/index.js:475:33)
    at /root/scan/node_modules/web3-core-requestmanager/src/index.js:147:9
    at XMLHttpRequest.request.onreadystatechange (/root/scan/node_modules/web3-providers-http/src/index.js:77:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/root/scan/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/root/scan/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/root/scan/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/root/scan/node_modules/xhr2/lib/xhr2.js:469:24)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:11979) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Downgrading to 0.20 did not work for me -- everything gets returned as 0 or 0x.

@rhlsthrm

I tried your way:

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
let c = new web3.eth.Contract(abi, keyaddress);

web3.eth.call({
             to: keyaddress,
             data: c.methods.developer().encodeABI()
}).then(balance => {console.log(balance)});

web3.eth.call({
        to: keyaddress,
        data: c.methods.ownersNum().encodeABI()
}).then(balance => {console.log(balance)});

console log:

0x

These are both incorrect

screen shot 2018-05-14 at 19 11 56

This got fixed with https://github.com/ethereum/web3.js/pull/2608 and will be released this week.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oktapodia picture oktapodia  ·  3Comments

connectdotz picture connectdotz  ·  3Comments

TinyWJL picture TinyWJL  ·  3Comments

zamoore picture zamoore  ·  3Comments

nivida picture nivida  ·  3Comments