Closed dzarezenko closed 6 years ago
Maybe the network environment of your plugin is not synchronized with your contract. Try switching.
then 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 .call()
to fail about 5% of the time. The issue was fixed after switching metamask network to Custom RPC and connected it to a node that I myself am hosting, and the issue disappeared.
version 1.0.0-beta.33 still has this problem. Anyone has already solved 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... I am using web3@1.0.0-beta.37 on windows7 Truffle v4.1.14 npm: '6.4.1'. Ganache is running and my app works fine. However, if I use .call() I get the error "contract.images(...).call is not a function"
What is contract.images
?
@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 web3@1.0.0-beta.34. 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:
const stateEvents = await Atl.getPastEvents('EventName', {
filter: {a: b},
fromBlock: 0,
toBlock: 'latest',
}, { from: fromAddress });
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.
const Election = new web3.eth.Contract(abi, contractAddress, { from: web3.eth.defaultAccount }); I were using incorrect contract address
web3.eth.getTransactionCount(address, function (err, nonce) {
const functionAbi = Election.methods.mymethod().encodeABI();
var details = {
'nonce': nonce,
'gasPrice': web3.utils.toHex(web3.utils.toWei('20', 'gwei')),
'gas': 6721975,
'from': address,
'to': contractAddress,
'value': 0,
'data': functionAbi,
};
const transaction = new EthereumTx(details);
transaction.sign(Buffer.from(pk, 'hex') )
var rawData = '0x' + transaction.serialize().toString('hex');
console.log(rawData);
web3.eth.sendSignedTransaction(rawData)
.on('transactionHash', function(hash){
console.log(['transferToStaging Trx Hash:' + hash]);
})
.on('receipt', function(receipt){
console.log(['transferToStaging Receipt:', receipt]);
res.send(receipt);
})
.on('error', console.error);
});
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 when i was trying to load tokenbalance as javascript version of the token smart contract
here is my code : const token = new web3.eth.Contract(Token.abi, tokenData.address) this.setState({ token }) let tokenBalance = await token.methods.balanceOf(this.state.account).call() this.setState({ tokenBalance: tokenBalance.toString() })
@razik-r : your Token.abi
is probably wrong.
oh my god ..tkysm !! I was trying to solve the problem like 6 hours so what happened is that when I imported the token contract and other contract I made some typo errors
I did this import EthSwap from '../abis/EthSwap.json' import Token from '../abis/EthSwap.json'
instead of this : import EthSwap from '../abis/EthSwap.json' import Token from '../abis/Token.json'
Hi,
I am trying to get
ERC20
tokens balance on some address withweb3.js
lib but received this error:My code: