0

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?

Argon
  • 13
  • 2
  • What do you mean by "successful transaction"? Do you need to catch an event when it was included in a block? Or do you need to check if it was (or wasn't) reverted? – Petr Hejda Jul 09 '21 at 09:01
  • @PetrHejda What I mean is, the Ether was successfully deposited at my_address. For example, I don't want to log a transaction if it was unsuccessful. For example, I put a conditional under the txHash and tested for it. But the txHash is generated even before the Ether arrives. I wouldn't like to log a transaction if it hasn't been successful. – Argon Jul 09 '21 at 23:24

0 Answers0