I am attempting to create a button on my dapp to send Ethereum. I would like to log a bit of the data in my own database after the transaction is successful. I don't want to log the data in my db until AFTER I know the transaction was successful. Is there a way to do this in Javascript?
Here is my code:
sendEthButton.addEventListener('click', () => {
let userETH = document.getElementById("inputId").value;
var wei_val = userETH*10e17;
var hexString = wei_val.toString(16);
ethereum
.request({
method: 'eth_sendTransaction',
params: [
{
from: accounts[0],
to: my_address,
//value: '0x6f05b59d3b20000',
value: hexString,
gasPrice: '',
gas: '',
},
],
})
.then((txHash) => console.log(txHash))
.catch((error) => console.error);
});
I know that I can test for the txHash, but that doesn't indicate whether or not the transaction was successful, just whether or not it was successfully initiated.
How can I test for a successful transaction through JS?