I want to add a loader to UI when there is a click on confirm transaction popup on metamask. When user clicks on confirm I want to show the loader until the transaction is confirmed. Is there a way to handle this?? Is there any event??
Ethers.js has a very simple solution for this question:
const provider = new ethers.providers.Web3Provider(window.ethereum); let tx = await contract.method(...) let txConfirm = await provider.getTransaction(tx.hash) ///perform operation only after "Confirm" is clicked in MetaMask
See docs on provider.getTransaction() here: https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/-%23-Provider-getTransactionReceipt