I’m building a web dApp using React + TypeScript + ethers.js.
When a Stop Loss (SL) or Take Profit (TP) level is reached, my frontend calls a function that sends a transaction to close the position.
Since the transaction uses the MetaMask signer (from BrowserProvider(window.ethereum)), MetaMask always opens a confirmation popup and requires the user to click Confirm.
For SL/TP auto-close, I want to send the transaction without showing the MetaMask confirmation popup and without any user interaction.
Is it technically possible to send a blockchain transaction using MetaMask without user confirmation?
Code:
javascriptconst pollAndAutoClose = async () => {
const price = await contract.priceFor(Date.now() / 1000);
const spot = parseFloat(ethers.formatUnits(price, 18));
for (const pos of positions) {
const hitSL = pos.stopLoss > 0 && spot <= pos.stopLoss;
const hitTP = pos.takeProfit > 0 && spot >= pos.takeProfit;
if (!hitSL && !hitTP) continue;
await contract.connect(signer).closePosition(pos.id);
// MetaMask popup appears here
}
};