Get MetaMask "Receipt" after token transfer

Hey, I was wondering if anyone knew how to get the callback receipt from MetaMask after a 1155 transfer to another account. I tried the Mint receipt that works for my minting function. However, it does not work for transfers. How should I call it back?

//Mint Receipt (WORKS)
.on("receipt", function(receipt){
    alert(("Minting Done!"))
})

//Transfer Receipt ---> (DOESN'T WORK)
.on("receipt", function(receipt){
    alert(("Transfer Done!"))
})

what you get if you use something like this:

.on('transactionHash', function(hash){
    ...
})
.on('receipt', function(receipt){
    ...
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.on('error', console.error); // If a out of gas error, the second parameter is the receipt.

code taken from here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#id86

1 Like

How do I add those to through Moralis Web3? Here is what I had in my code.

async function transfer_ticket(){

   
    const options = {type: "erc1155",  
    receiver: "0x0B2b64cd00f8656D07c5880AfAf0Bb89688D4d1F",
    contractAddress: "0x882a1e44e429e054d0643ea10ca00a909452302f",
    tokenId: 1,
    amount: 1}
let result = await Moralis.transfer(options)

.on('transactionHash', function(hash){
    alert(("Transfer done!"))
})
   
} 

you can try:

Moralis.transfer(options)
.on('transactionHash', function(hash){
   console.log("hash");
})
.on('receipt', function(receipt){
    console.log("receipt");
})
.on('confirmation', function(confirmationNumber, receipt){ console.log("confirmation") })
.on('error', console.error);

but I’m not sure if it will work

this is the code in case that you want to look at the code from Moralis SDK:

1 Like

You get receipt now already

let receipt = await Moralis.transfer(options)

receipt will be receipt when transaction is mined and receipt is generated
The function will throw an error if transactions fails.

Currently you dont get all events like in web3 library
We will add support for each event very soon also.

1 Like
Moralis.transfer(options).then((receipt) => {
   console.log(receipt);
   alert(("Done!"));
}).catch((e) => alert(e.message))
1 Like

This worked! Thank you so much. This was the last piece to my puzzle! I appreciate everyone in the Moralis community! :pray: here is the final code for anyone reading after.

async function transfer_ticket(){

   
    const options = {type: "erc1155",  
    receiver: "0x0B2b64cd00f8656D07c5880AfAf0Bb89688D4d1F",
    contractAddress: "0x882a1e44e429e054d0643ea10ca00a909452302f",
    tokenId: 1,
    amount: 1}

let receipt = await Moralis.transfer(options).then((receipt) => {
    console.log(receipt);
    alert(("Done!"));
 }).catch((e) => alert(e.message))


} 

You’ll have to wait about 5-10 seconds for the alert to come back.

2 Likes

Nicee :sunglasses:

Happy BUIDLing :man_mechanic:

1 Like

Hi @DevWill

I want to inform you that some time ago we added support for callback events:

https://docs.moralis.io/moralis-server/sending-assets#callbacks-promises-events-new