Closed mwaeckerlin closed 5 years ago
How are you setting this.state.account
.
@tmashuang, here:
updateAccounts(cb = null) {
this.state.web3.eth
.getAccounts()
.then(
accounts => {
this.setState(prev => ({
accounts: [],
account: prev.account || accounts[0] || ""
}));
accounts.forEach(account => {
this.state.web3.eth.getBalance(account).then(balance => {
this.setState(prev => ({
accounts: [
...prev.accounts,
{
account: account,
balance: balance
}
]
}));
});
});
if (cb) cb();
}
)
}
BTW, I have at exactly this position a really strange behavior with web3.js
and my attempts to add a proper error handling:
This works:
updateAccounts(cb = null) {
this.state.web3.eth
.getAccounts()
.then(
[… same as above …]
)
.once("transactionHash", console.log)
.once("receipt", console.log)
.on("confirmation", console.log)
.on("error", console.log);
}
But this, which is exactly according to the documentation fails and nothing is called:
updateAccounts(cb = null) {
this.state.web3.eth
.getAccounts()
.once("transactionHash", console.log)
.once("receipt", console.log)
.on("confirmation", console.log)
.on("error", console.log)
.then(
[… same as above …]
);
}
Any idea, what's wrong here and how to implement a proper error handling?
EDIT: Only the following works to get a correct result in case error and in case of success:
updateAccounts(cb = null) {
this.state.web3.eth
.getAccounts((error, accounts) => {…})
}
Unfortunately, with Metamask, I still get an error.
So the new promises from Web3 1.0.0 do not work at all… :-1:
BTW: It makes a difference on the kind of error whether i access the react webpage in development environment through the built-in react server or as production deployment in webpack through a nodejs/express server (running in a docker image). But: Both fail, and both get TypeError: NetworkError when attempting to fetch resource.
Unfortunately, my reproduction has not produced these errors, if you could provide a repo that has these errors I would gladly take a look. Your code snippet reminded me to Truffle, so I used their package to try to reproduce your issue here. I noticed that when I upgraded the default web3
package from 1.0.0-beta.37
to 1.0.0-beta.41
it did break.
@tmashuang, I can reproduce the problem with a simple react-metamask-test demo:
git clone https://github.com/mwaeckerlin/react-metamask-test
cd react-metamask-test
npm install
solc --overwrite --combined-json abi,bin -o src/contracts/json src/contracts/test.sol
ganache-cli -d --db ${HOME}/tmp/ganache/db -i 123456
BROWSER=none npm start
DataCloneError: The object could not be cloned
YES, @tmashuang, you are 100% right: Setting "web3": "1.0.0-beta.37"
in package.json
fixes the problem! Thank you very much!
Now: On which side is the problem, in web3.js or in MetaMask? And is there already an open ticket to fix this?
Please add a link to the the ticket in web3.js or in MetaMask, then close this one.
I would assume web3.js since downgrading solved it, but maybe they are experimenting with something we haven't adjusted for yet.
@tmashuang, since the problem seems to be known, there is probably an open ticket? Or where did you get this information from?
Could you please add a link to the ticket?
I am getting the same error when using metamask on polygon network on ff browser
i getting the error in Firefox too. How did you resolve this?
Getting the same error here. I'm using a local hardhat.
It is NOT a network error since I'm getting no errors when making many static calls or invoking the getPastEvents function, but as of today it happens when trying to send a transaction (which is not the same error when a transaction is reverted). This error is not consistent, however: perhaps in 1h it stops happening.
This happens in Firefox 126.0 with Metamask on Ubuntu. Assume all the other packages (project-related things, even Hardhat) as stable as possible.
This issue seems to exists in #1779 (and #2301), but both have been closed long ago, even though the problem is not solved, at least not for me. Since I cannot reopen it and get no answer to my comments there, I open a new bug and provide all the information I have. Unfortunately the whole source code is too huge to append, so I provide the snippets where the problem occurs.
Describe the bug
Using:
Without Metamask the exactly same code works (using the fallback to localhost, connecting to canache-cli). In a nodejs / express environment without react, it works. So I suppose, it is something about Metamask and React in combination.
startup of canache:
first error message is
TypeError: NetworkError when attempting to fetch resource
on lineawait window.ethereum.enable();
in the following Initiatlization code:Using Web3 0.20.7
On line
await window.ethereum.enable();
, I always get an error:At the end, creating a contract, web3 fails with silly error messages without a useful context, such as:
Using Web3 1.0.0-beta41
Same in web3 1.0.0-beta41:
The message Weitere Informationen links to a Firefox page.
When I try to deploy a contract in Web3 1.0.0-beta41, I get no more information than:
To Reproduce Steps to reproduce the behavior:
Expected behavior Web3 should be correctly initialized, a contract should be deployed.
Browser details (please complete the following information):
Additional context
The code, where the contract is deployed: