I’m building a small local HTML page based on the Moralis transfer ERC20 documentation tutorial.
I am testing the Event Callbacks on a transfer of a new coin I created on the Testnet (Mumbai) of the Polygon network.
The transfer did occured and the coin arrived in the destination wallet, but the javascript gave an error before the callback that would just display the returned values of each callback. Without the awaitReciepts: false the transfer work the same way and I don’t get error, but I want to play around withcalbacks.
ERROR : Uncaught (in promise) TypeError: tx.on is not a function at transfer (index.html:119)
I tought it could have been the await keyword since we define callbacks waiting for the response may not have been required, but I get the same error with ot without it.
SERVER URL : https://wc9uugow39y5.usemoralis.com:2053/server
transfer = async (amount, destination) => {
const CoinContractAddress = "0x...";
const options = {type: "erc20",
amount: Moralis.Units.Token(amount, "18"),
receiver: destination,
contractAddress: CoinContractAddress
,awaitReceipts: false // to get event callbacks
};
const tx = await Moralis.transfer(options);
tx.on("transactionHash", (hash) => { console.log("Transaction Hash: "); console.log(hash); })
.on("receipt", (receipt) => { console.log("Receipt: "); console.log(receipt); })
.on("confirmation", (confirmationNumber, receipt) => { console.log("confirmation: "); console.log(confirmationNumber); console.log(", Receipt: "); console.log(receipt); })
.on("error", (error) => { console.log("Error: "); console.log(error); });
}