Best way to test for a successful deposit

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);
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? Would that data be outside the purview of this interaction? Do I have to just scrape Etherscan or something?

Is there a better way to do this through a Metamask API or something?

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings


  1. As far as I know, MetaMask does not offer the ability to confirm a transaction was successful. You can use an Etherscan API to confirm a transaction went through properly. It is a little more work as you will need to incorporate Etherscan’s API but that is how I have been doing it. I don’t know about the policy on links in this subreddit so I won’t link anything, but if you look up ‘etherscan API javascript’ you can find them.

Michael Arrington, Tim Draper and the Dawn of the Age of Crypto | by Anthony Perkins

$SCHN – Scrap Lives Matter