Tx.on not a function (SOLVED)

Hello people.
I suddenly have a problem when executing functions with “Moralis.executeFunction(options)”.

I always get the message “tx.on is not a function”.

It used to work. Do you have any idea what the problem could be? I am at my wit’s end.

Code snippet:

<script src="https://unpkg.com/moralis/dist/moralis.js"></script>

<script  type="text/javascript">
  
   async function EnableVoting() {
  
    const VotingABI = 'xxx'; //removed
    const VotingContract = 'xxx'; //removed
    const serverUrl = "xxx"; //removed
    const appId = "xxx"; //removed
    
    await Moralis.start({ serverUrl, appId });
			
    const web3 = await Moralis.enableWeb3();
			
    const options = {
			  contractAddress: VotingContract,
			  functionName: "EnableVoting",
			  abi: VotingABI,
			  msgValue: Moralis.Units.ETH("0"),
			  awaitReceipt: false // should be switched to false
			};

	const tx = await Moralis.executeFunction(options);

	tx.on("transactionHash", (hash) => { console.log(hash); })
	.on("receipt", (receipt) => { console.log(receipt); })
	.on("confirmation", (confirmationNumber, receipt) => { console.log(confirmationNumber); })
	.on("error", (error) => { console.log(error); });
			
   }
 
  
</script>

The transaction in MetaMask goes through without any problems, but as soon as the transaction is started, the error message “tx.on is not a function” appears.

We have released v1.0 of the SDK with breaking changes, please read: https://forum.moralis.io/t/moralis-js-sdk-v1-0-migration-to-ethers-js

In your case, you downgrade and can specify the version of moralis to a version before the update,

https://unpkg.com/[email protected]/dist/moralis.js
1 Like

The downgrade works.

A thousand thanks for the quick reply.

1 Like