Set up the ethereum-boilerplate and the completely untouched code was returning the following error on attempting transfers:
TypeError: txStatus.on is not a function
The transactions were still going through (Metamask balance updates) but the boilerplate UI gets stuck with a continuous spinner and no notifications. The relevant code is below:
const txStatus = await Moralis.transfer(options);
txStatus
.on("transactionHash", (hash) => {
openNotification({
message: "π New Transaction",
description: `${hash}`,
});
console.log("π New Transaction", hash);
})
.on("receipt", (receipt) => {
openNotification({
message: "π New Receipt",
description: `${receipt.transactionHash}`,
});
console.log("π New Receipt: ", receipt);
setIsPending(false);
})
.on("error", (error) => {
openNotification({
message: "π Error",
description: `${error.message}`,
});
console.error(error);
setIsPending(false);
});
A Moralis team member on discord mentioned that it might be due to switching from Web3.js to ethers that .on
was not working and that wait
would be better. So I refactored the code as below:
const txStatus = await Moralis.transfer(options);
await txStatus.wait("transactionHash", (hash) => {
openNotification({
message: "π New Transaction",
description: `${hash}`,
});
console.log("π New Transaction", hash);
});
await txStatus.wait("receipt", (receipt) => {
openNotification({
message: "π New Receipt",
description: `${receipt.transactionHash}`,
});
console.log("π New Receipt: ", receipt);
setIsPending(false);
});
await txStatus.wait("error", (error) => {
openNotification({
message: "π Error",
description: `${error.message}`,
});
console.error(error);
setIsPending(false);
});
console.log(txStatus);
This removes errors in the console but the stuck UI is still a problem. Logging txStatus
returns a valid transaction object. Any help would be appreciated
Terminal has no warnings
Moralis: 1.3.5
React-Moralis: 1.3.2
Node: 16.13.1
Thanks for taking the time to go through this.