Uncaught (in promise) TypeError: tx.on is not a function

Hi everyone,

I keep getting this error after installing ethereum-boilerplate and interacting with contracts using the contract tab.

The transaction is getting executed without any issue the only problem is that I’m not getting any response back and I don’t have any idea what is the problem

I have tried different networks, same issue.

Please someone help me out solving this problem. Thanks!

Is the transaction successful through the wallet?

Did you get any other error form your wallet?

The transaction is happening without any issue. The only problem is that I’m not able to get data back. I fixed it as I followed a different approach to notify the use about the transaction TX and receipt

const tx = await Moralis.executeFunction({
                  awaitReceipt: true,
                  ...options,
                });
                console.log(tx.hash);
                openNotification({
                  message: "Pending Transaction Transaction!",
                  description: "TX:" + tx.hash
                  });
                // Wait until the transaction is confirmed
                const receipt = await tx.wait();
                openNotification({
                  message: "Transaction confirmed!",
                  description: ""
                  });
                  
                console.log(receipt)

Instead of

tx.on("transactionHash", (hash) => {
                  setResponses({
                    ...responses,
                    [name]: { result: null, isLoading: true },
                  });
                  openNotification({
                    message: "🔊 New Transaction",
                    description: `${hash}`,
                  });
                  console.log("🔊 New Transaction", hash);
                })
                  .on("receipt", (receipt) => {
                    setResponses({
                      ...responses,
                      [name]: { result: null, isLoading: false },
                    });
                    openNotification({
                      message: "📃 New Receipt",
                      description: `${receipt.transactionHash}`,
                    });
                    console.log("🔊 New Receipt: ", receipt);
                  })
                  .on("error", (error) => {
                    console.error(error);
                  });
1 Like

Yes the tx.on is syntax for the web3.js library which Moralis doesn’t use anymore - that component hasn’t been updated.

Yes as mentioned by @glad, it is web3js syntax, if you would like to use web3js then you can’t use Moralis.executeFunction, but instead you need to use usual web3js syntax

Here is how you can use web3js for your web3 provider with Moralis

https://docs.moralis.io/moralis-dapp/web3/web3#web3.js