Web3.min.js:2 Uncaught (in promise) Error: Transaction has been reverted by the EVM: {


I am testing out my subscription method on the test network Sepolia. I tried using this paySubscription function on hardhat and it worked, but i need it on frontend in next.js and now it prompts me with metamask and when i submit the transaction i get Transaction reverted by evm error after about 15 seconds.

Here is the function i am trying to pay to, followed by my frontend function.

function paySubscription(uint256 _period) external payable virtual { 
        if(msg.value != ethFee * _period) revert FailedEthTransfer();
        if(paymentExpire[msg.sender] == 0) {
           paymentExpire[msg.sender] = (block.timestamp) + (_period * 30 days); 
        } else {
            paymentExpire[msg.sender] += _period * 30 days;
async function paySubscription() {
  // Check if MetaMask is installed
  if (
    typeof window.ethereum !== "undefined" ||
    typeof window.web3 !== "undefined"
  ) {
    const provider = window["ethereum"] || window.web3.currentProvider;
    const w3 = new Web3(provider);

    // Request account access
    const accounts = await ethereum.request({
      method: "eth_requestAccounts",

    const contract = new w3.eth.Contract(contractABI, contractAddress);

    const gasLimit = 200000;
    let gasPrice = await w3.eth.getGasPrice(); // Get current gas price
    let gasPriceGwei = w3.utils.fromWei(gasPrice, "gwei");
    let increasedGasPrice = (parseFloat(gasPriceGwei) * 2).toString();
    let gasPriceWei = w3.utils.toWei(increasedGasPrice, "gwei");
    const valueToSend = w3.utils.toWei("1", "ether");

    const receipt = await contract.methods.paySubscription(1).send({
      from: accounts[0],
      value: valueToSend,
      gas: gasLimit,
      gasPrice: gasPriceWei,

    return receipt;
  } else {
1 Like

I can provide you with the full error if that helps ,

web3.min.js:2 Uncaught (in promise) Error: Transaction has been reverted by the EVM:
  "blockHash": "0xee343a4824a7a1cb78aefaf040adc95fd8df9516d03b0202488710cc0ffb1b4d",
  "blockNumber": 3878815,
  "contractAddress": null,
  "cumulativeGasUsed": 23993,
  "effectiveGasPrice": 50000000009,
  "from": "0x363588a028a2cdaa7400f0e8ea3b6f2e19dddcaa",
  "gasUsed": 23993,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0xefed8093e6907544da4486b37994582fb36ceda4",
  "transactionHash": "0x732628e5d136f4911aa2ae3090f91bb8c891be2c9ae314de8ddbc79ec9809847",
  "transactionIndex": 0,
  "type": "0x2",
  "events": {}
    at Object.TransactionError (web3.min.js:2:964004)
    at Object.TransactionRevertedWithoutReasonError (web3.min.js:2:964370)
    at eval (web3.min.js:2:980392)
    at h (web3.min.js:2:1103143)
    at Generator.eval (web3.min.js:2:1104512)
    at Generator.eval [as next] (web3.min.js:2:1103514)
    at t (web3.min.js:2:1097739)
    at s (web3.min.js:2:1097960)
    at eval (web3.min.js:2:1098019)
    at new Promise (<anonymous>)
    at eval (web3.min.js:2:1097893)
    at eval (web3.min.js:2:980730)

I believe that:

  • When using type 1, you should specify gasPrice
  • When using type 2, you should specify maxFeePerGas and maxPriorityFeePerGas

But according to the error-message, you have specified type 2 and gasPrice.

You haven't specified type 2 explicitly, so this is probably the default used by web3.js.

So what you can do is to explicitly specify type: "0x1" when you execute the transaction.

FYI, this problem is also posted as an issue on web3.js GitHub repository.