web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.39k stars 4.97k forks source link

Error: overflow (fault="overflow", operation="toNumber" #3897

Closed ngugcx closed 3 years ago

ngugcx commented 3 years ago
var Web3 = require("web3")
const erc20_abi = require("erc-20-abi")

var web3 = new Web3(Web3.givenProvider || "wss://mainnet.infura.io/ws/v3/xxxxxxxxxxxxxxxxxxx");

(async () => {
    var addr = "0x9469D013805bFfB7D3DEBe5E7839237e535ec483"
    const token = new web3.eth.Contract(erc20_abi, addr)
    var symbol = await token.methods.symbol().call()
    console.log(symbol)
})().catch((e) => {console.log(e)})

Expected behavior

Print token symbol.

Actual behavior

Error: overflow (fault="overflow", operation="toNumber", value="37219173669927928934343007185464907322285017302421996643363583465474819620864", code=NUMERIC_FAULT, version=bignumber/5.0.13)
    at Logger.makeError (/root/monitor/node_modules/@ethersproject/logger/lib/index.js:179:21)
    at Logger.throwError (/root/monitor/node_modules/@ethersproject/logger/lib/index.js:188:20)
    at throwFault (/root/monitor/node_modules/@ethersproject/bignumber/lib/bignumber.js:295:19)
    at BigNumber.toNumber (/root/monitor/node_modules/@ethersproject/bignumber/lib/bignumber.js:152:13)
    at /root/monitor/node_modules/@ethersproject/abi/lib/coders/array.js:89:60
    at Array.forEach (<anonymous>)
    at Object.unpack (/root/monitor/node_modules/@ethersproject/abi/lib/coders/array.js:85:12)
    at TupleCoder.decode (/root/monitor/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
    at AbiCoder.decode (/root/monitor/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22)
    at ABICoder.decodeParametersWith (/root/monitor/node_modules/web3-eth-abi/lib/index.js:304:30)
    at ABICoder.decodeParameters (/root/monitor/node_modules/web3-eth-abi/lib/index.js:285:17)
    at Contract._decodeMethodReturn (/root/monitor/node_modules/web3-eth-contract/lib/index.js:470:22)
    at Method.outputFormatter (/root/monitor/node_modules/web3-eth-contract/lib/index.js:760:42)
    at Method.formatOutput (/root/monitor/node_modules/web3-core-method/lib/index.js:147:54)
    at sendTxCallback (/root/monitor/node_modules/web3-core-method/lib/index.js:523:33)
    at Object.callback (/root/monitor/node_modules/web3-core-requestmanager/lib/index.js:308:9) {
  reason: 'overflow',
  code: 'NUMERIC_FAULT',
  fault: 'overflow',
  operation: 'toNumber',
  value: '37219173669927928934343007185464907322285017302421996643363583465474819620864'
}

Steps to reproduce the behavior

Replace xxxx in the code with infura project id. Then run the nodejs script.

Logs

Environment

web3: v1.3.3

GregTheGreek commented 3 years ago

I'm not at my computer right now. But calling a contract will return a big number, and you cannot console.log a big number since it will try to call toNumber(). Please try calling .toString() on the result.

ngugcx commented 3 years ago

I'm not at my computer right now. But calling a contract will return a big number, and you cannot console.log a big number since it will try to call toNumber(). Please try calling .toString() on the result.

console.log(symbol.toString())

It made no difference. From the call stack, it looks like the error is not thrown from my code.

Clonescody commented 3 years ago

Hi there, I'm also facing this issue. For more details, I noticed this happening on the Maker MKR token ( 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2 ). Interesting point, this is happening on the name() function call.

There is my code

const loadERC20BalanceRequest = function* ({ erc20TokenAddress, isLast }) {
  try {
    const ethAddress = yield select((store) => store.infos.address);
    const web3 = new Web3(yield select((store) => store.nodes.web3Provider));
    let newBalance;
    try {
      const tokenContract = new web3.eth.Contract(humanStandardTokenABI, erc20TokenAddress);

      const { balanceOf, name, symbol } = tokenContract.methods;

      const balanceObj = balanceOf(ethAddress);
      const nameObj = name();
      const symbolObj = symbol();

      const balanceForToken = yield call(balanceObj.call);
      // error thrown on next call
      const nameForToken = yield call(nameObj.call);
      const symbolForToken = yield call(symbolObj.call);

      newBalance = {
        amount: `${web3.utils.fromWei(balanceForToken.toString())}`,
        symbol: symbolForToken,
        name: nameForToken,
      };

      yield put({
        type: 'TOKEN_BALANCE_LOADED',
        newBalance,
      });

      if (isLast) {
        yield put({
          type: 'ERC20_BALANCE_LOADED',
        });
      }
    } catch (errorTokenLoading) {
      yield put({
        type: 'LOAD_TOKEN_BALANCE_FAILED',
        erc20TokenAddress,
        error: errorTokenLoading.toString(),
      });
    }
  } catch (errorContract) {
    yield put({
      type: 'LOAD_ERC20_BALANCE_FAILED',
      erc20TokenAddress,
      error: errorContract.toString(),
    });
  }
};

LOAD_TOKEN_BALANCE_FAILED is triggered with following error :

Error: overflow (fault="overflow", operation="toNumber", value="35000214728014336407470934256024915466671168103574785725052718905953538277376", code=NUMERIC_FAULT, version=bignumber/5.0.14)
    at Logger.makeError (index.js:166)
    at Logger.throwError (index.js:175)
    at throwFault (bignumber.js:287)
    at BigNumber.toNumber (bignumber.js:146)
    at array.js:74
    at Array.forEach (<anonymous>)
    at unpack (array.js:70)
    at TupleCoder.decode (tuple.js:22)
    at AbiCoder.decode (abi-coder.js:88)
    at ABICoder.../../../../../../../workspace/defi/defi-graph/node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParametersWith (index.js:304)
    at ABICoder.../../../../../../../workspace/defi/defi-graph/node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParameters (index.js:285)
    at Contract.../../../../../../../workspace/defi/defi-graph/node_modules/web3-eth-contract/lib/index.js.Contract._decodeMethodReturn (index.js:470)
    at Method.outputFormatter (index.js:760)
    at Method.../../../../../../../workspace/defi/defi-graph/node_modules/web3-core-method/lib/index.js.Method.formatOutput (index.js:147)
    at sendTxCallback (index.js:523)
    at index.js:308
    at XMLHttpRequest.request.onreadystatechange (index.js:98)

I am loading a dozen other tokens without any problem, it's been specific to MKR for me.

alexon1234 commented 3 years ago

Same for me with MKR

ndorf commented 3 years ago

Same problem with SAI (address 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359), as well as MKR. Most other tokens seem to work fine.

MarkoCen commented 3 years ago

I had this issue when executing smart contract on a pool lack of liquidity. it will throw this error when the token reserves extremely low

bobinmad commented 3 years ago

Today noticed same problem with PASTA (0xe54f9e6ab80ebc28515af8b8233c1aee6506a15e) as well as MKR and SAI

cryptokek commented 3 years ago

Having the same issue. Seems like it happens when calling symbol and name methods when they have crazy number values saved there. e.g. https://etherscan.io/address/0xe54f9e6ab80ebc28515af8b8233c1aee6506a15e#readContract check the symbol and name values.

We've worked around this by sending raw web3 requests. As such it seems to be a bug with web3 library.

const rawWeb3Call = async (address: string, method: "name" | "symbol") => {
  const data = JSON.stringify({
    jsonrpc: "2.0",
    method: "eth_call",
    params: [
      {
        to: address,
        data: web3.utils.sha3(`${method}()`),
      },
      "latest",
    ],
    id: 1,
  });

  const config: AxiosRequestConfig = {
    method: "post",
    url: "[nodeUrl]",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  };

  try {
    const response = await axios(config);
    return web3.utils.hexToNumberString(response.data.result);
  } catch (error) {
    console.error(error);
    return false;
  }
};
VexyCats commented 3 years ago

Still having this issue - any resolution or fix?

tambu22 commented 3 years ago

Already posted on issue 4004, but I think this is the one with more information.

I have the same issue, with version "web3": "^1.3.5"

I'm trying to call a router contract function getAmountOut:

Function ABI:

{
    inputs: [
      { internalType: "uint256", name: "amountIn", type: "uint256" },
      { internalType: "address[]", name: "path", type: "address[]" },
    ],
    name: "getAmountsOut",
    outputs: [
      { internalType: "uint256[]", name: "amounts", type: "uint256[]" },
    ],
    stateMutability: "view",
    type: "function",
  }

In some coins with extremely low value i get the overflow error:

Error: overflow (fault="overflow", operation="toNumber", value="3963877391197344453575983046348115674221700746820753546331534351508065746944", code=NUMERIC_FAULT, version=bignumber/5.1.0)
    at Logger.makeError (/home/nico/Documents/bsc/node_modules/@ethersproject/logger/lib/index.js:180:21)
    at Logger.throwError (/home/nico/Documents/bsc/node_modules/@ethersproject/logger/lib/index.js:189:20)
    at throwFault (/home/nico/Documents/bsc/node_modules/@ethersproject/bignumber/lib/bignumber.js:305:19)
    at BigNumber.toNumber (/home/nico/Documents/bsc/node_modules/@ethersproject/bignumber/lib/bignumber.js:153:13)
    at /home/nico/Documents/bsc/node_modules/@ethersproject/abi/lib/coders/array.js:90:60
    at Array.forEach (<anonymous>)
    at Object.unpack (/home/nico/Documents/bsc/node_modules/@ethersproject/abi/lib/coders/array.js:85:12)
    at TupleCoder.decode (/home/nico/Documents/bsc/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
    at AbiCoder.decode (/home/nico/Documents/bsc/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22)
    at ABICoder.decodeParametersWith (/home/nico/Documents/bsc/node_modules/web3-eth-abi/lib/index.js:304:30)
    at ABICoder.decodeParameters (/home/nico/Documents/bsc/node_modules/web3-eth-abi/lib/index.js:285:17)
    at Contract._decodeMethodReturn (/home/nico/Documents/bsc/node_modules/web3-eth-contract/lib/index.js:470:22)
    at Method.outputFormatter (/home/nico/Documents/bsc/node_modules/web3-eth-contract/lib/index.js:760:42)
    at Method.formatOutput (/home/nico/Documents/bsc/node_modules/web3-core-method/lib/index.js:147:54)
    at sendTxCallback (/home/nico/Documents/bsc/node_modules/web3-core-method/lib/index.js:523:33)
    at /home/nico/Documents/bsc/node_modules/web3-core-requestmanager/lib/index.js:308:9
    at XMLHttpRequest.request.onreadystatechange (/home/nico/Documents/bsc/node_modules/web3-providers-http/lib/index.js:98:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/nico/Documents/bsc/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/home/nico/Documents/bsc/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/home/nico/Documents/bsc/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/home/nico/Documents/bsc/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:215:7)
    at endReadableNT (_stream_readable.js:1183:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  reason: 'overflow',
  code: 'NUMERIC_FAULT',
  fault: 'overflow',
  operation: 'toNumber',
  value: '3963877391197344453575983046348115674221700746820753546331534351508065746944'
}

My code:

try {
    priceArray = await router.methods.getAmountsOut(1000000000, path).call({});
  } catch (error) {
    await eventLog(error, CONSTANTS.ERRORS.FETCHING_PRICES);
    return undefined;
  }

To reproduce: npm i web3

const Web3 = require("web3");
const web3 = new Web3("https://bsc-dataseed1.binance.org:443");
const ABIRouter = [
  {
    inputs: [
      { internalType: "uint256", name: "amountIn", type: "uint256" },
      { internalType: "address[]", name: "path", type: "address[]" },
    ],
    name: "getAmountsOut",
    outputs: [
      { internalType: "uint256[]", name: "amounts", type: "uint256[]" },
    ],
    stateMutability: "view",
    type: "function",
  },
];
const router = new web3.eth.Contract(
  ABIRouter,
  "0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F"
);
const path = [
  "0x81e4d494b85a24a58a6ba45c9b418b32a4e039de",
  "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
  "0xe9e7cea3dedca5984780bafc599bd69add087d56",
];

const test = async () => {
  try {
    console.log(router.methods);
    priceArray = await router.methods.getAmountsOut(1000000000, path).call({});
    console.log(priceArray[2].toString()); //if works prints the big number
  } catch (error) {
    console.log(error); //print the erro
    return undefined;
  }
};

test();

Edit: I've already tried supplying the function with the number in string, web.BN, BigNumber and Hex

tambu22 commented 3 years ago

@cryptokek I'm trying to make the same as you, but dont get some things, my method is a router contract call for getting prices, so I make this code:

const Web3 = require("web3");
const axios = require("axios");
const web3 = new Web3("https://bsc-dataseed1.binance.org:443");

const rawWeb3Call = async (address, method, amout, path) => {
  console.log(`${method}("${amout}",[${path}])`);
  const data = JSON.stringify({
    jsonrpc: "2.0",
    method: "eth_call",
    params: [
      {
        to: address,
        data: web3.utils.sha3(`${method}("${amout}",[${path}])`),
      },
      "latest",
    ],
    id: 1,
  });

  const config = {
    method: "post",
    url: "https://bsc-dataseed1.binance.org:443",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  };

  try {
    const response = await axios(config);
    const result = await web3.utils.hexToNumberString(response.data.result);
    console.log(result, response.data);
    return result;
  } catch (error) {
    console.error(error);
    return false;
  }
};

const path = [
  "0x81e4d494b85a24a58a6ba45c9b418b32a4e039de",
  "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
  "0xe9e7cea3dedca5984780bafc599bd69add087d56",
];

rawWeb3Call(
  "0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F",
  "getAmountsOut",
  1000000000,
  path
);

but my reply always is 0x, it's okay with the way al added the params to the data?

You can check my original code and error in my prev message.

Edit: Fixed some code issues

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

ZentaChainAdmin commented 3 years ago

Any update ? Otherwise, the bot will close this issue.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

ndorf commented 3 years ago

Still an issue in version 1.5.2

luncht1me commented 3 years ago

Can't test my smart contract because of this :( Trying to call method in truffle and it's throwing this overflow error each time, something in the logger running a toNumber() when should be handling as a BigNumber.

nazarhussain commented 3 years ago

I was able to reproduce this issue with web3 1.5.2.

var Web3 = require("web3")
const erc20_abi = require("erc-20-abi");

var web3 = new Web3(Web3.givenProvider || "wss://mainnet.infura.io/ws/v3/xxxxxxx");

(async () => {
    var addr = "0x9469D013805bFfB7D3DEBe5E7839237e535ec483"
    const token = new web3.eth.Contract(erc20_abi, addr)
    var symbol = await token.methods.symbol().call()
    console.log(JSON.stringify(symbol))
})().catch((e) => {console.log(e)})

The problem comes in ABI Coder somewhere when it tries to decodeParametersWith following values.

{
  outputs: [ { internalType: 'string', name: '', type: 'string' } ],
  bytes: '52494e4700000000000000000000000000000000000000000000000000000000',
  loose: false,
}

The internal codec of @thersproject tries to convert this hex value to a number which is a 32 bytes value. This end up in causing this overflow error. We need to further debug why the @ethersporjecct codec is trying to convert this full hex string as an offset, rather it should just use zero as offset.

https://github.com/ethers-io/ethers.js/blob/4166b2753d0d6b230a3a22b5a2b6c4e1906a7af7/packages/abi/lib/coders/array.js#L91-L92

nazarhussain commented 3 years ago

That was a tricky one, but finally figured it out and it's not any issue related to web3.

@ngugcx The contract with address 0x9469D013805bFfB7D3DEBe5E7839237e535ec483 is not ERC-20 compliance. As per the the erc-20 standard the symbol property must be of type string . But for that contract that property is defined as byte32. As you can see by the image blow and also can verify with the following link.

image

You can also verify its value from the ethscan read contract page as well.

image

So for the given erc-20-abi it cause the error as it tries to convert the bytes to the string.

To make it work, you must have the correct ABI for the contract. For that you can go to ethscan page > code > Contract ABI > Copy / Export the ABI.

Use that ABI instead of erc-20-abi and it will work fine.

const Web3 = require("web3");
const contractAbi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"stop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_disable","type":"bool"}],"name":"disableTransfers","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newController","type":"address"}],"name":"changeController","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_guy","type":"address"},{"name":"_wad","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"name_","type":"bytes32"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"src","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"stopped","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newCap","type":"uint256"}],"name":"changeCap","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"issue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_guy","type":"address"},{"name":"_wad","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"wad","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_amount","type":"uint256"}],"name":"destroy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"push","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"dst","type":"address"},{"name":"wad","type":"uint256"}],"name":"move","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"start","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"transfersEnabled","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_amount","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"guy","type":"address"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"src","type":"address"},{"name":"guy","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"claimTokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"src","type":"address"},{"name":"wad","type":"uint256"}],"name":"pull","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"controller","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_token","type":"address"},{"indexed":true,"name":"_controller","type":"address"},{"indexed":false,"name":"_amount","type":"uint256"}],"name":"ClaimedTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"data","type":"bytes"}],"name":"ERC223Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"sig","type":"bytes4"},{"indexed":true,"name":"guy","type":"address"},{"indexed":true,"name":"foo","type":"bytes32"},{"indexed":true,"name":"bar","type":"bytes32"},{"indexed":false,"name":"wad","type":"uint256"},{"indexed":false,"name":"fax","type":"bytes"}],"name":"LogNote","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"guy","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"src","type":"address"},{"indexed":true,"name":"dst","type":"address"},{"indexed":false,"name":"wad","type":"uint256"}],"name":"Transfer","type":"event"}];

const web3 = new Web3(
  Web3.givenProvider ||
    "wss://mainnet.infura.io/ws/v3/xxxxxxxxxxxxxxxxx"
);

(async () => {
  console.log("%%%%% WEB3: ", web3.version);
  var addr = "0x9469D013805bFfB7D3DEBe5E7839237e535ec483";
  const token = new web3.eth.Contract(contractAbi, addr);
  var symbol = await token.methods.symbol().call();
  console.log(JSON.stringify(symbol));
})().catch((e) => {
  console.log(e);
});

And you get the following output.

%%% WEB3:  1.5.2
"0x52494e4700000000000000000000000000000000000000000000000000000000"
nazarhussain commented 3 years ago

I am closing this issue as its reached to conclusion as mentioned above. For everyone following this issue is advised to verify if they are using the correct ABI for their contracts and also verify if the contract itself is erc-20 compliant.

moonman369 commented 2 years ago

Getting the same error in remix while trying to call a view function that returns an array.

CarlosARendon commented 2 years ago

Use the function ethers.utils.formatEther(userBalance) to solve this problem

AN-Drew207 commented 1 year ago

How could this problem being solved as I'm trying to get an array from a function