Skip to content
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

Closed
quantumproducer opened this issue May 14, 2018 · 21 comments
Closed

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

quantumproducer opened this issue May 14, 2018 · 21 comments
Assignees
Labels
Bug Addressing a bug

Comments

@quantumproducer
Copy link

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
Copy link

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
Copy link
Author

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

@asselstine
Copy link

asselstine commented May 15, 2018 via email

@quantumproducer
Copy link
Author

@asselstine
Copy link

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

@quantumproducer
Copy link
Author

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

@asselstine
Copy link

@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
Copy link

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
Copy link

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
Copy link

same problem

@asselstine
Copy link

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

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

@netpoe
Copy link

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
Copy link

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

@mastashake08
Copy link

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
Copy link
Author

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

@mastashake08
Copy link

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

@Rex-L
Copy link

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
Copy link

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
Copy link

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 Addressing a bug label Nov 28, 2018
@nivida
Copy link
Contributor

nivida commented Mar 30, 2019

This got fixed with the PR #2608 and will be released asap.

@nivida nivida closed this as completed Mar 30, 2019
@Sreesankar-G-Warrier
Copy link

Sreesankar-G-Warrier commented Aug 13, 2020

Hi, am also having the same issue and I got this error from my browser

web3.min.js:1 Uncaught (in promise) Error: Couldn't decode from ABI: 0x
at o.formatOutputInt [as _outputFormatter] (web3.min.js:1)
at o.decode (web3.min.js:1)
at web3.min.js:1
at Array.forEach ()
at b.decodeParameters (web3.min.js:1)
at M.d._decodeMethodReturn (web3.min.js:1)
at f.outputFormatter (web3.min.js:1)
at f.formatOutput (web3.min.js:1)
at o (web3.min.js:1)
at web3.min.js:1

Am using these versions
Truffle v5.1.37 (core: 5.1.37)
Solidity v0.5.16 (solc-js)
Node v12.18.3
Web3.js v1.2.1

By using this web3 version I got another error from the browser.

index.js:338 Uncaught (in promise) Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
at h.decodeParameters (index.js:338)
at B.d._decodeMethodReturn (index.js:572)
at l.outputFormatter (index.js:935)
at l.formatOutput (index.js:169)
at o (index.js:653)
at a (util.js:689)
at b.run (browser.js:153)
at p (browser.js:123)

so I changed my web3 version to this cdn.

https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.34/dist/web3.min.js

Please help me to solve this issue and am very new to this tech. So, I hope, I will get a detailed explanation about this issue. Thanks in Advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests