Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34830

How to reject ethers.js Metamask transaction programatically?

I'm designing an NFT minting interface and when the user hits mint it pops up MetaMask transaction confirmation dialog:

enter image description here

Here is the code that I call to invoke minting:

 // in a Redux saga, with parameters appropriately filled.
 // I have a "mint" method in my smart contract.
 const txn = yield contract.mint(q.payload.amount, { value: ethers.utils.parseEther(etherValue.toString()) });

For better user experience, I'm guiding the user also on my webpage to continue on MetaMask. I want to put a "Cancel" button on my webpage, when pressed, will reject the transaction and close the MetaMask notification dialog.

Is it possible to reject a transaction this way? I know it's (obviously) not possible to confirm programatically, but I was wondering if I can reject it through code without user actually hitting "Reject" button.

Upvotes: 0

Views: 362

Answers (1)

Yilmaz
Yilmaz

Reputation: 49671

I do not think that you can programmatically access Metamask.

When you call a contract function on javascript, you are first connecting to metamask wallet which holds the private key for the connected account.

Once you are connected to this account, second step is to send the transaction to rpc servers by clicking on Confirm button.

Let's say, you create your own logic, you connected to an account with its private key without Metamask, you showed a modal to the user to confirm or reject, the user has to somehow click on a button to close.

Upvotes: 1

Related Questions