I make a contract method call using .send()
method:
contractInstance.methods.pay(itemId).send({from: defaultAccount, value: web3.utils.toWei(String(price*1.0000001)), gas: '1000000'},
function(error, transactionHash) {
if(error)
alert("You tried to pay below the price or payment failure! " + err);
})
How to be notified when the transaction fully happened (cannot be canceled by clicking Cancel in MetaMask anymore)? Is it called a confirmation?
If I just add .on('confirmation')
:
contractInstance.methods.pay(itemId).send({from: defaultAccount, value: web3.utils.toWei(String(price*1.0000001)), gas: '1000000'},
function(error, transactionHash) {
if(error)
alert("You tried to pay below the price or payment failure! " + err);
})
.on('confirmation', function(receipt){ showFilesWithMessage(); });
it does nothing (showFilesWithMessage()
is not called).
web3.js 1.2.9.
Addition:
When I "follow the example on the official docs":
contractInstance.methods.pay(itemId).send({from: defaultAccount, value: web3.utils.toWei(String(price*1.0000001)), gas: '1000000'})
.on('transactionHash', function(hash){
console.log('transactionHash');
})
.on('receipt', function(receipt){
console.log('receipt');
})
.on('confirmation', function(confirmationNumber, receipt) {
console.log('confirmation', confirmationNumber);
showFilesWithMessage();
})
.on('error', console.error); // If a out of gas error, the second parameter is the receipt.
the confirmation
event is not issued either! Instead I get only transactionHash
event.
How to get the confirmation event for .send()
?
If I just add...
- how exactly do you add it? Please share a complete piece of code, not fragments of it. Otherwise, it is impossible to tell you what exactly you are doing wrong..on
and a callback function passed as one of the parameter. If you wanna catch all 4 events (transaction hash, receipt, error and 24 confirmations), then get rid of the fallback and follow the example on the official docs.