Common Transaction Errors & 'Exception Thrown in Contract Code'

Try Tangem secure wallet →

Table of contents


Introduction

If you use MetaMask as your software wallet, you will run into failed transactions. Expect that. Some failures are simple (insufficient gas). Others show a scary line: "Exception thrown in contract code." That message looks dire. But it usually means a contract reverted or threw an error during execution. I’ve seen this when swapping tokens, approving allowances, and while connecting Ledger devices. I’ll show how to diagnose the error and what to try next.

Who this guide is for (and who should look elsewhere)

This is for people who use MetaMask (extension or mobile) to interact with DeFi, swap tokens, and sign contract transactions. You’re comfortable checking block explorers and willing to increase gas or replace pending txs. If you manage large balances or need maximum security, pair MetaMask with a hardware wallet and read hardware-best-practices.

Quick checklist — first 60 seconds fixes

  1. Unlock MetaMask and confirm the correct account is selected. Short step. Saves time.
  2. Confirm you’re on the right network (Ethereum vs Polygon vs Avalanche). Wrong network = instant fail.
  3. Ensure you have enough ETH (or native token) for gas.
  4. Open the contract or transaction on a block explorer and check the failure reason.
  5. If using a hardware device, open its blockchain app and reconnect. (Yes, seriously.)

If these don’t work, keep reading for a structured debug process.

What "Exception thrown in contract code" actually means

At the EVM level the call failed. The contract executed and hit a condition that caused it to revert or throw. Common causes:

Revert messages are sometimes returned by the node and sometimes not. That means you may see a terse "exception thrown" without extra text. Why? Because not all contracts include a readable revert reason, and some nodes strip it during estimation.

Step-by-step debugging (How to fix a failed tx)

  1. Copy the tx hash and open it on a block explorer. Look for "Status: Failed" and any revert reason. (Image: failed-tx-on-explorer - alt text placeholder)
  2. Decode the input data. Which function failed? If it’s a swap function like swapExactTokensForTokens, slippage or approvals are likely suspects.
  3. Check token allowances. If the contract needs transferFrom, verify allowance > amount. See revoke-approvals for managing approvals.
  4. Check gas: was the tx out-of-gas? If estimate failed, try increasing gas limit by 20–30% (but don’t massively overpay). Read gas-fees-and-eip-1559 for fee strategy.
  5. Simulate the call (eth_call) or use a block explorer’s "read/write" simulate feature (if available). This often shows the revert reason.
  6. If there’s a pending transaction with the same nonce, either wait or replace it with a higher-fee tx (same nonce). See stuck-pending-transactions.
  7. If the dApp constructs an unusual transaction type (account abstraction or a bundled tx) check the dApp docs. MetaMask may show "tx not supported" for uncommon signing schemes; in that case the dApp needs to provide a compatible flow (see account-abstraction).

What I’ve found: most "Exception thrown" cases boil down to either allowance problems or trying to call contract code that checks an access role. Test with tiny amounts first.

Ledger & hardware-specific failures

Keywords you might search: "metamask transaction failed ledger" or "metamask unknown error ledger." These usually come from one of these issues:

Step-by-step for Ledger-like problems:

  1. Open the blockchain app on the device and unlock the account.
  2. Update firmware and device apps.
  3. Try a different USB cable or port, and restart the browser.
  4. If MetaMask shows "tx not supported" or fails to finish, consult connect-ledger and ledger-troubleshooting or the dedicated guide how-to-fix-ledger-tx.

But there’s a human factor: I once signed without opening the Ledger app and it failed silently. Simple to miss, costly to debug.

Chrome extension / popup problems — MetaMask tx not popping up on chrome browser

If a transaction never causes MetaMask to open for confirmation try this checklist:

If none of the above works, see extension-troubleshooting and mobile-sync-troubleshooting.

Common error messages decoded (table)

Error shown What it usually means Quick fix
Exception thrown in contract code Contract reverted during execution (no extra message) Check tx on explorer, decode input, simulate call
VM Exception / execution reverted Revert with or without reason Read revert reason, check allowances, check access control
Gas estimation failed eth_estimateGas returned error (contract would revert) Simulate, increase gas limit manually, re-check inputs
MetaMask Tx Signature: User denied User rejected signature on device/extension Reconfirm and sign; on hardware ensure app is open
tx not supported / unknown signing method DApp used a non-standard signing flow Check dApp docs; may need a different wallet or updated integration

Preventing future failures — practical security tips

Conclusion & next steps (CTA)

A "metamask transaction error" or "metamask transaction error exception thrown in contract code" is often fixable with methodical checks: network, balance for gas, allowances, and contract simulation. If you hit hardware-specific failures like "metamask transaction failed ledger" or "metamask unknown error ledger", make sure your device app and firmware are current and follow the hardware connection guides.

Need hands-on help? Start with these guides: transaction-troubleshooting, connect-ledger, and stuck-pending-transactions. If you want to avoid the problem entirely, practice small test transactions and keep approvals tight. I’ve been using this workflow daily for months — it saves time and prevents dumb losses.

If one of these steps fixed your issue, great. If not, copy the tx hash, open it on a block explorer, and follow the simulation steps above. Then check the relevant troubleshooting pages linked above.

Try Tangem secure wallet →