-
Notifications
You must be signed in to change notification settings - Fork 5k
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
TypeError: token.methods.balanceOf(...).call(...).on is not a function #1089
Comments
I also received this bug - upgrading to |
Same issue facing in "web3": "^1.0.0-beta.23",
|
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 _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:
|
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 |
@lionello you are right. Its actually wrong behaviour. > 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 |
I added the |
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 "). Once I updated the address, refreshed, and created a new instance through my browser, it worked. |
Started getting this error today in beta.29 after I updated my locally deployed Smart Contract with a constructor (it previously had none) |
Same here... calling a const contract method with web3js 1.0.0-beta.30 intermittently triggers:
|
same here |
1 similar comment
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 |
1 similar comment
same here! Latest version: 1.0.0-beta.33 |
@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 |
@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 First, I added these two helper functions:
Then, in order to invoke an onchain-stateless function, I use:
And in order to invoke an onchain-stateful function, I use:
Of course, in the helper functions, you may get rid of the |
i found the same problem, but was because the address of the contract was wrong.
|
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 |
Maybe the network environment of your plugin is not synchronized with your contract. Try switching. |
1.0.0-beta.35 , same issue, and sth more wired that at the begining the code runing correctly , but after I install another package keythereum , all codes about contract get the errorthen I deploy a new contract with the same code , and everything goes ok this time. |
Hey ,em...... ,is this problem solved? is there a solution? |
Double check the abi. I've got this 'bug' after minor changes in contract code without updating the abi. |
One possibility is that the blockchain node Metamask uses is corrupt / has false data. Found that error in my dapp today (metamask mainnet node) and it was causing the lookup of one constant |
version 1.0.0-beta.33 still has this problem. |
@xoxoj this problem means you try to call the method of a contract which is not existing on this address. |
@k06a I am sure it has |
Any ideas on how to resolve this issue would be highly appreciated... |
What is |
@quantumproducer thank you for your answer. You were right, I was mistakenly calling "images" which is an array and not a function. I figured it out soon after posting my previous message. |
I have the same behavior like @dacarley had. Sometimes it works and sometimes it does not. Interestingly enough, it just started appearing without any obvious reason. The first thing I tried is to run a local geth node instead of using the Infura API, this did not change anything. My local geth node is running in light mode. I also reverted my code base to the state when I deployed the contracts originally to make sure I am using the ABI as deployed. I was calling some functions on my contracts that modify the state before all started and to be honest at this point it might have been that my ABIs we're not entirely correct however since the functions finished without error I assume it should be fine. Furthermore, as mentioned sometimes I am able to read the data from the contract so it is on chain. I am by now at the point to simply try and redeploy everything to see if the behavior goes way. I am working on the Ropsten network and currently running [email protected]. Open for any suggestions. Edit: The behavior is the same with Metamask in the web browser as with my own client that uses a HttpProvider. |
I have the same problem. ABI is definitely in sync with deployed contract. web3-provider-engine, HttpProvider, ganache-cli, embark. Started seemingly randomly today and occurs seemingly unpredictably. I get it when calling contract.getPastEvents (there are no events in the log that match the type) |
OK, I was able to fix by specifying a from address when calling contract.getPastEvents:
|
Sorry that was wrong. It just randomly worked a couple fo times then started failing again |
I were receiving same error and finally, I were able to fix issue as per following.
i were using incorrect contract address in 'to' field of details of transaction. I corrected contract address at both places and code worked correctly. I hope it would be helpful for someone. Happy Coding! |
got this error : Unhandled Rejection (TypeError): token.methods.balanceOf is not a function here is my code : |
@razik-r : your |
oh my god ..tkysm !! I was trying to solve the problem like 6 hours I did this instead of this : |
Hi,
I am trying to get
ERC20
tokens balance on some address withweb3.js
lib but received this error:My code:
The text was updated successfully, but these errors were encountered: