New issue

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

Error: Couldn't decode uint256 from ABI: 0x #1629

Open
quantumproducer opened this Issue May 14, 2018 · 19 comments

Comments

@quantumproducer

quantumproducer commented May 14, 2018

I created this Contract:

https://etherscan.io/address/0xfc7e86dbd205d02f97316995d8ace5d0afb9fe62#readContract

You can see in the Read Contract section that ownersNum is a uint with a current value of 1.

I copied the address

0xFc7e86dBD205D02F97316995d8AcE5D0AFB9fe62 and validated with https://tokenmarket.net/
ethereum-address-validator

cat keyaddress.js
module.exports = '0xFc7e86dBD205D02F97316995d8AcE5D0AFB9fe62'

In my node server, I created abi.js and copied the abi from etherscan

cat abi.js
module.exports = [{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"owners","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ownersNum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"payout","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"developer","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"buyKey","outputs":[{"name":"success","type":"bool"}],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"buyer","type":"address"}],"name":"QuantumPilotKeyPurchased","type":"event"}];

Now I try to read the ownersNum value in memory:

const fs = require('fs');
const express = require('express');
const Web3 = require('web3');
const BigNumber = require('bignumber.js');
const sigUtil = require('eth-sig-util');
const abi = require('./abi');
const keyaddress = require('./keyaddress');

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

let on = c.methods.ownersNum().call();
        console.log(on);
        return;


//below is never reached, the above crashes
//  on.then(function(a,b) {
          //console.log(a);
          //console.log(b);
  //});

And this happens

     ... (contract details)
       name: 'buyKey',
       outputs: [Array],
       payable: true,
       stateMutability: 'payable',
       type: 'function',
       signature: '0xe95db6f9' },
     { anonymous: false,
       inputs: [Array],
       name: 'QuantumPilotKeyPurchased',
       type: 'event',
       signature: '0x55985f5332be13e699aaa51a5d3c003941f60e74af84533ebab5626b72cf3f51' } ] }
Promise { <pending> }
(node:5079) 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:5079) 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:5079) [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.

This used to work fine while I was testing on Kovan. Now I switch to MainNet, upgrade web3, getting this error. I was on beta27, upgraded today to 34, same error, slightly different printout but same result.

@asselstine

This comment has been minimized.

asselstine commented May 15, 2018

I have the same issue. I'm using MetaMask if that helps.

I noticed that it seemed to be occurring for a transaction whose recipient 'to' was 0x0000...

@quantumproducer

This comment has been minimized.

quantumproducer commented May 15, 2018

@asselstine you got an error reading a transaction?
Do you get the same error when reading from a smart contract?

@asselstine

This comment has been minimized.

asselstine commented May 15, 2018

@quantumproducer

This comment has been minimized.

@asselstine

This comment has been minimized.

asselstine commented May 15, 2018

I reset my local Ganache instance and it seemed to resolve the issue. At least for now ;)

@quantumproducer

This comment has been minimized.

quantumproducer commented May 15, 2018

@asselstine is your geth synced? I'm reading elsewhere that your geth node needs to be synced. Unable to sync: ethereum/mist#3097

@asselstine

This comment has been minimized.

asselstine commented May 17, 2018

@quantumproducer I've isolated the problem down to one thing:

An eth_call message is being sent to the node with a zero to address.

I.e.:

eth_call:
to: "0x0000000000000000000000000000000000000000"

It really doesn't like that. The error may be in my code...I'm investigating. Regardless it would be handy for web3 to complain if 'to' is null.

@asselstine

This comment has been minimized.

asselstine commented May 17, 2018

I can confirm: one of my Truffle artifacts was not deployed to the network I was on. Sending eth_call to the zero addresses results in the '0x' encoding issue.

@voratham

This comment has been minimized.

voratham commented Jun 14, 2018

I got problem same as when I testing
a smart contract on "https://remix.ethereum.org" it working and correct, But when I using web3js 1.0.0-beta.34 call smart contract not working.

Example

function getData(uint _index) public constant returns(uint){
uint data = datas[msg.sender].numbers[_index].numbers;
return data;
}

screen shot 2561-06-14 at 10 29 58

@wangjj9219

This comment has been minimized.

wangjj9219 commented Jun 17, 2018

same problem

@asselstine

This comment has been minimized.

asselstine commented Jun 17, 2018

A VM exception in a constant function call will cause Web3 to throw

Couldn't decode *** from ABI: 0x

@netpoe

This comment has been minimized.

netpoe commented Jun 17, 2018

I'm getting this error with mainnet infura, but not in ropsten infura.

Using web3@1.0.0.beta.33:

    let nonce = await this.getNonce(this.simpleCrowdsale)

    let txOptions = {
      from: this.wallet.getAddress(),
      gas: Web3.utils.toHex(this.gas),
      gasLimit: Web3.utils.toHex(this.gas),
      gasPrice: Web3.utils.toHex(this.defaultGasPrice),
      data: txObject.encodeABI(),
      nonce: Web3.utils.toHex(nonce)
    }

    try {
      let signedTx = await this.web3.eth.accounts.signTransaction(txOptions, this.wallet.getInstance().privateKey)
      let receipt = await this.web3.eth.sendSignedTransaction(signedTx.rawTransaction) // error happens here
@marcosmartinez7

This comment has been minimized.

marcosmartinez7 commented Jun 22, 2018

Same problem here using Geth 1.8 and web3@1.0.0.beta.33 when trying to invoca a call

@mastashake08

This comment has been minimized.

mastashake08 commented Jun 27, 2018

I am having same issue what is status of ticket? I am using web3@1.0.0.0.beta.34

Code

addToken: function(){
        var contract;
        var abi = [{"constant":true,"inputs":[],"name":"mintingFinished","outputs": 
[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_releaseTime","type":"uint256"}],"name":"mintTimelocked","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
        contract = new this.web3.eth.Contract(abi, this.scriptHash, {from: '0x'+this.eth.address})
        console.log(contract);
        contract.methods.balanceOf(this.eth.address).call().then(function(result){
          console.log(result)
        });
      }

Error

formatters.js?2147:174 Uncaught (in promise) Error: Couldn't decode uint256 from ABI: 0x
at SolidityTypeUInt.formatOutputUInt (formatters.js?2147:174)
at SolidityTypeUInt.SolidityType.decode (type.js?f4eb:252)
at eval (index.js?bbaf:327)
at Array.forEach (<anonymous>)
at ABICoder.decodeParameters (index.js?bbaf:326)
at Contract._decodeMethodReturn (index.js?d100:459)
at Method.outputFormatter (index.js?d100:812)
at Method.formatOutput (index.js?6248:163)
at sendTxCallback (index.js?6248:475)
at eval (index.js?176c:147)
@quantumproducer

This comment has been minimized.

quantumproducer commented Jun 27, 2018

Try syncing... I ended up using parity because geth doesn't work on harddisks

@mastashake08

This comment has been minimized.

mastashake08 commented Jun 27, 2018

I'm connecting to infura so parity and geth are irrelevant in my case.

@Rex-L

This comment has been minimized.

Rex-L commented Jul 13, 2018

The different Ether network (Main Ethereum Network、 Ropsten Test Network、private Network、 private Network) have different contractAddress. so change contractAddress

@hems

This comment has been minimized.

hems commented Jul 13, 2018

indeed turns out this was happening because i was mistakenly connected to a different testnet than the one i thought i was!

i believe ideally a more friendly error could be yielded, such as 'not found' or 'not existent' something a little bit less cryptic

@justindthomas

This comment has been minimized.

justindthomas commented Aug 6, 2018

For posterity (in case anyone else happens upon this with a similar challenge) I was also struggling with this problem just now and it turned out to be self-sabotage; I tested the Destructible pattern on my Rinkeby test ERC20 token before I deployed an update to mainnet by calling the "destroy()" method and then forgot I did that. So my Rinkeby token contract address was correct - as was my ABI. But the token had been invalidated.

@nivida nivida self-assigned this Aug 10, 2018

@nivida nivida added the bug label Nov 28, 2018

@nivida nivida added this to To do in 1.0 Milestone Nov 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment