[SOLVED] Not able to trigger event callbacks on an ERC20 transfer

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); });
}

you are using latest Moralis SDK version?

Seems so and my servers were created last week.
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>

it doesn’t matter the server in this case, you can do that without even having a server

@orlandumike, it looks like the parameter is awaitReceipt = true, instead of awaitReceipts

@cryptokid I see the error with the extra “s”. I tryed every permutations of the await, true and false and the documentation is right.

It’s awaitReceipt: false with the await on the transfer call.

A little typical type mistake, thak you for spotting it, have a great day !

1 Like