0

I am trying to set up a structure that will receive payment with the sendTransaction method. But there is a small problem. The sendTransaction method works fine, but has the user completed the transfer? Did the transfer go to the destination wallet? I can't control like Is there a way to do these checks?

You can think like this.

sendEthButton.addEventListener('click', () => {
  ethereum
    .request({
      method: 'eth_sendTransaction',
      params: [
        {
          from: accounts[0],
          to: {sellerAdress},
          value: {totalAmount}
        },
      ],
    })
    .then((txHash) => console.log(txHash))
    .catch((error) => console.error);
});

Thanks to this method, the transfer notification is sent to the customer's metamask. There is no problem here. But did the client approve the transfer request from Metamask? Is the transfer complete? Or did the customer not respond to the transfer notification? Is there any method to do such queries?

Briefly, how can I check the transfer status to see if the payment has been completed?

2
  • you can check the balance before and after the transaction.
    – Adam Boudj
    Commented Mar 23, 2022 at 7:46
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Mar 23, 2022 at 7:46

1 Answer 1

0

You just need to get the receipt using the txHash

https://www.quicknode.com/docs/ethereum/eth_getTransactionReceipt https://web3js.readthedocs.io/en/v1.7.1/web3-eth.html#gettransactionreceipt

Assume transactions have 3 steps

  1. Pending (tx sent but not mined): you won't get a lot of params in the call such as blockHash
  2. Approved (Mined and executed successfully): status param will be true
  3. Rejected (Mined but execution failed): status param will be false

I recommend you use a library to do those checks like ethers.js or web3js, they will automatically subscribe and notify you, you can even choose to accept the transaction only when a number of confirmations (Blocks on top of the block where your tx was mined) happens to protect against 51% attacks

https://web3js.readthedocs.io/en/v1.7.1/callbacks-promises-events.html?highlight=receipt

Best of luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.