Closed dzarezenko closed 6 years ago
I also received this bug - upgrading to ^1.0.0-beta.22
fixed this for me.
Same issue facing in "web3": "^1.0.0-beta.23",
this.contractObj.methods.balanceOf(address).call(function (err, wieBalance) {}
Error: Couldn't decode uint256 from ABI: 0x
at SolidityTypeUInt.formatOutputUInt [as _outputFormatter] (formatters.js:162)
at SolidityTypeUInt.webpackJsonp.../../../../web3-eth-abi/src/type.js.SolidityType.decode (type.js:252)
at index.js:327
at Array.forEach (<anonymous>)
at ABICoder.webpackJsonp.../../../../web3-eth-abi/src/index.js.ABICoder.decodeParameters (index.js:326)
at Contract.webpackJsonp.../../../../web3-eth-contract/src/index.js.Contract._decodeMethodReturn (index.js:451)
at Method.outputFormatter (index.js:798)
at Method.webpackJsonp.../../../../web3-core-method/src/index.js.Method.formatOutput (index.js:162)
at sendTxCallback (index.js:453)
at index.js:144
at XMLHttpRequest.request.onreadystatechange [as __zone_symbol__ON_PROPERTYreadystatechange] (index.js:64)
at XMLHttpRequest.wrapFn (zone.js:1166)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:499)
at invokeTask (zone.js:1540)
at XMLHttpRequest.globalZoneAwareCallback (zone.js:1566)
also tried with ^1.0.0-beta.22 but issue remains same
Hey all, I was also receiving this bug and it turned out to be a slight difference in the ABI of my contract and the one I was using in my application. Not sure if there's another cause, but I would make sure that you're using the most recent version of your contract's ABI.
We are getting the same issue, only on Ropsten testnet
no luck yet, anybody have a solution, please list
I have resolved this with enclosing functionality into Promise
:
_getTokenBalance : function (address) {
var _this = this;
return new Promise(function(resolve, reject) {
var tokenBalance = 0;
_this.contract.methods.balanceOf(address).call().then(function (result) {
var tokensWei = result;
console.log("Tokens Wei: " + tokensWei);
_this.contract.methods.decimals().call().then(function (result) {
var decimals = result;
console.log("Token decimals: " + decimals);
tokenBalance = parseFloat(tokensWei) / Math.pow(10, decimals);
console.log("Token balance: " + tokenBalance);
resolve(tokenBalance);
});
});
});
}
and call it like:
this._getTokenBalance(address).then(function(tokenBalance) {
// ...
});
For now, you can use -
web3.eth.call({
to: address,
data: contract.methods.balanceOf(address).encodeABI()
}).then(balance => {})
I disagree with the fix that was introduced in 15ffd55. This should not be handled by such low-level conversion code.
So to understand that right, the contract returns 0x
? If so then this is certainly not a good fix, and i changed it in develop to make sure 0x will fail.
@lionello you are right. Its actually wrong behaviour.
So if it would return 0
the value would look like:
> web3.eth.call({to: '0x6d72f4097b093518114ac0ba54d7c9fd73eecc05', data: '0x39f6ca500000000000000000000000000000000000000000000000000000000000000000'})
"0x0000000000000000000000000000000000000000000000000000000000000000"
Though if it throws, it looks like:
> web3.eth.call({to: '0x4597b8c3b40d96dc0365ced9dc9b56b81247120d', data: '0x39f6ca500000000000000000000000000000000000000000000000000000000000000000'})
"0x"
Therefore the raw value is also empty if it failed. This is a problem of how the token contract is build and not one of web3.js
So you need to catch the errors of the call, as it throws inside the contract, rather then returning anything expected.
@frozeman Yeah, that's more like it.
I'd really like to see some test that warrants the !param.rawValue
clauses you've added. For the current tests, those clauses don't appear to changes the behavior at all, suggesting that they might be superfluous.
I added the !param.rawValue
only for int, uint and bool, as here we don't want it to be accidentally interpreted as 0
, or false
same error in version 1.0-beta.28. How to solve it?
same error in version 1.0-beta.29. Anybody figure this out yet?
I was getting this with beta.26. I figured out that my deployed and compiled contracts were out of sync and that I was calling a function in my contract that didn't exist in the old contract. In other words, I made a change to my contract, compiled and deployed. I hadn't updated the address to my deployed contract (which I used to created instances of another contract that in my web ui was something like "add new
Started getting this error today in beta.29 after I updated my locally deployed Smart Contract with a constructor (it previously had none) Calling any constant function causes the error, other functions work fine. Would very much appreciate some insight. Updating to beta.30 did not help
Same here... calling a const contract method with web3js 1.0.0-beta.30 intermittently triggers:
Error: Couldn't decode uint256 from ABI: 0x
at SolidityTypeUInt.formatOutputUInt [as _outputFormatter] (/Users/tu/node_modules/web3-eth-abi/src/formatters.js:174:15)
at SolidityTypeUInt.SolidityType.decode (/Users/tu/node_modules/web3-eth-abi/src/type.js:252:17)
at /Users/tu/node_modules/web3-eth-abi/src/index.js:327:49
at Array.forEach (<anonymous>)
at ABICoder.decodeParameters (/Users/tu/node_modules/web3-eth-abi/src/index.js:326:13)
at Contract._decodeMethodReturn (/Users/tu/node_modules/web3-eth-contract/src/index.js:459:22)
at Method.outputFormatter (/Users/tu/node_modules/web3-eth-contract/src/index.js:811:46)
at Method.formatOutput (/Users/tu/node_modules/web3-core-method/src/index.js:162:54)
at sendTxCallback (/Users/tu/node_modules/web3-core-method/src/index.js:453:33)
at Object.<anonymous> (/Users/tu/node_modules/web3-core-requestmanager/src/index.js:144:9)
at /Users/tu/node_modules/web3-providers-ws/src/index.js:76:44
at Array.forEach (<anonymous>)
at W3CWebSocket.WebsocketProvider.connection.onmessage (/Users/tu/node_modules/web3-providers-ws/src/index.js:53:36)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/tu/node_modules/yaeti/lib/EventTarget.js:107:17)
at W3CWebSocket.onMessage (/Users/tu/node_modules/websocket/lib/W3CWebSocket.js:234:14)
at WebSocketConnection.<anonymous> (/Users/tu/node_modules/websocket/lib/W3CWebSocket.js:205:19)
at WebSocketConnection.emit (events.js:160:13)
at WebSocketConnection.processFrame (/Users/tu/node_modules/websocket/lib/WebSocketConnection.js:547:26)
at /Users/tu/node_modules/websocket/lib/WebSocketConnection.js:321:40
at process._tickCallback (internal/process/next_tick.js:150:11)
same here
same here
This still remains :(
Did this never get fixed? Still getting it in beta 33...
same here! Latest version: 1.0.0-beta.33
same here! Latest version: 1.0.0-beta.33
So, I have fixed this and number of other things with just better ethereum js lib https://github.com/ethers-io/ethers.js
@jamboj Error: Couldn't decode uint256 from ABI: 0x
This is not a problem in web3js - it happens when the contractAddress is wrong, or the bytecode of the contract does not implement the ABI you provide.
Example :
const web3 = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"));
const contractInstance = new web3.eth.Contract(abi, contractAddress);
contractInstance.methods.yourMethod().call().then((res) => { ... });
Double check your contractAddress
and the abi
That appears to be an incorrect statement. I have a token contract that works fine for most calls to balanceOf, but sometimes, I receive “0x” as the result, rather than “0x0000000000000000000000000000000000000000000000000000000000000000”. It’s inconsistent in it’s behavior, and has nothing at all to do with the ABI - this is the RAW value coming back over the RPC connection.
On March 29, 2018 at 11:10:35 AM, Stefaan Ponnet (notifications@github.com) wrote:
@jamboj https://github.com/jamboj Error: Couldn't decode uint256 from ABI: 0x -> This is not a problem in web3js - it happens when the contractAddress is wrong, or the bytecode of the contract does not implement the ABI you provide.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ethereum/web3.js/issues/1089#issuecomment-377323913, or mute the thread https://github.com/notifications/unsubscribe-auth/AA60g1ffgKEvWWmknhcQteT4JLlj6jd_ks5tjSOZgaJpZM4PsL_n .
No, this issue isn’t depend on abi or address. I have every 10 seconds call that just read a balance, and in ~5-10% I’ve got this error.
Let me rephrase : providing a non-matching contract / ABI throws the same error as above , so that could be something you want to check.
I'll try to reproduce the error you describe - and see if I can come up with something. Thanks for pointing that out.
same here
version 1.0.0-beta.33
still has this problem.
Anyone has already solved this problem?
Still having this problem here as well
Has this problem - turns out my metamask was on a different network (mainnet), where the contract was not deployed. Fixed after switching back to ropsten.
@dacarley @sponnet I would like to get to the bottom of this. It doesn't look like its a problem of web3.js, in fact it should error on a wrong output. Maybe this problem lies withing geth, or its an out of gas issue. More input would be welcome.
Using web3 1.0 and MetaMask. Simple call of a getter function with
var MyContract = new web3.eth.Contract(abi, address);
MyContract.methods.myFunction().call().then(console.log);
Same issue.
@frozeman , my findings up to now
Using a local nodeJS script ( not in a browser )
...Couldn't decode uint256 from ABI: 0x
when a wrong ABI or contract address , or network was provided ( bytecode does not match the given ABI )In a browser
I'll try to look if I can isolate or reproduce the issue using the Metamask provider.
TL;DR : I got this issue because of the provider I ran.
In case it can help anyone on this issue.
I got the error Error: Couldn't decode uint256 from ABI: 0x
, everything was correctly setup : good ABI, good contract address.
I'm using geth
to run my private blockchain in order to test.
My issue was because I didn't start any miner, the network was responding but it didn't return the expected response, it returned something like "0x", thus the error. Remix doesn't seem to be bothered much about this format so Remix is not really helping.
I think the error is because of the provider in 100% of cases, the origin of the issue can be multiple : no miner, bad contract address, ABI not corresponding to the deployed contract, etc.
Maybe Web3 should let the user handle this issue, I wasn't able to handle/catch this error.
I had the same problem, upgrading to 1.0.0-beta.34 from 1.0.0-beta.33 fixed it for me.
@Slaals can you expand on
I think the error is because of the provider in 100% of cases
I am using infura and am not running my own node.
@haydenadams Infura is retuning you an empty response for some reasons (most probably, must investigate more on that). This error could be raised for some reasons I'm not aware of.
I don't know how you can fix this since you have no control on Infura, Make sure your ABI is the good one and you call the good contract address on the good provider URL.
I had the issue because I didn't correctly setup my private provider using Geth.
@Slaals can you explain? I'm running geth, but no miner. I didn't think we needed a from: address to call contracts with.
@quantumproducer I didn't go deeper about this issue, I just found why I had this one in the first place. AFAIK you have to run a miner in order to make this work.
When you run geth
make sure you open the console
; once you're in the console, simply type miner.start()
, it will start to mine (sync and mine if it's desync). After that you shouldn't have this error again.
@Slaals I don't want to mine, I just want to use geth to read from transactions. I tried miner.start() then running my code, same issue.
facing this problem in web3 version 1.0.0-beta.34
with metamask & Ropsten
Does anyone have a proper solution?
@Aniket-Engg this problem means you try to call the method of a contract which is not existing on this address.
I have this issue on Kovan at the moment and I can confirm I am using the correct ABI. I have recompiled it so many times, and I always get the same result. I also deployed my contract in web3 in the same closure and I still can't call the method.
After some review, I seem to have been having an issue similar to @Slaals I didn't realize my Kovan node had stopped silently syncing. Although I could see the transaction on Etherscan, I didn't have the block yet.
Same problem when working with Parity (on a local host).
However, this seems to be due to an incorrect usage of Web3
, and I was able to resolve it as follows:
First, I added these two helper functions:
async function call(transaction) {
let success = await web3.eth.personal.unlockAccount(OWNER_ADDRESS, OWNER_PASSWORD);
let gas = await transaction.estimateGas({from: OWNER_ADDRESS, gasPrice: GAS_PRICE});
return await transaction.call({from: OWNER_ADDRESS, gasPrice: GAS_PRICE, gas: gas});
}
async function send(transaction) {
let success = await web3.eth.personal.unlockAccount(OWNER_ADDRESS, OWNER_PASSWORD);
let gas = await transaction.estimateGas({from: OWNER_ADDRESS, gasPrice: GAS_PRICE});
return await transaction.send({from: OWNER_ADDRESS, gasPrice: GAS_PRICE, gas: gas});
}
Then, in order to invoke an onchain-stateless function, I use:
await call(myContract.methods.myMethod(put your args here if needed));
And in order to invoke an onchain-stateful function, I use:
await send(myContract.methods.myMethod(put your args here if needed));
Of course, in the helper functions, you may get rid of the unlockAccount
part and / or the estimateGas
part if they are not necessary for your system behavior requirements.
i found the same problem, but was because the address of the contract was wrong. So, for me the real issue is "an invalid contract can be mapped to an object without throw an exception". Then, when you try to call the method the exception is throwed.
"web3": "^1.0.0-beta.34",
"web3-core-requestmanager": "^1.0.0-beta.34",
"web3-eth": "^1.0.0-beta.34",
"web3-eth-contract": "^1.0.0-beta.34"
I am having the same issue, My dapp is using infura ropsten node as geth provider, Its a Nodejs app, and I have triple checked my Contract ABI and address, If i downgrade to Web3 0.20 i do not see this error with the same provider, and setup. I only encounter this problem if i use web 1.0
Hi,
I am trying to get
ERC20
tokens balance on some address withweb3.js
lib but received this error:My code: