Error while calling purchase NFT function

Hello everyone, I am facing an error called: Transaction submission failed: missing revert data (action="estimateGas", data=null, reason=null, transaction={ "data": "0xee2729e50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000312c0649d0c0ec8e9e594b8e7971c47be4f12ad4", "from": "0xa5E4645137a9024bA06Ad7d65513E4a08cB9131f", "to": "0xAAEB20aD80ad21daC9F83B463c5d2Fe72B38e01e" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.4.0)
while calling the callPurchaseItem function to buy an NFT.
Let me share the contract functions here:
Child Contract:

   function purchaseItem(uint256 tokenId, address to) external payable {
        uint256 _totalPrice = getTotalPrice(tokenId);
        MarketItem storage item = marketItems[tokenId];
            msg.value >= _totalPrice,
            "not enough matic to cover item price and market fee"
        require(!item.sold, "item already sold");
        feeAccount.transfer(_totalPrice - item.price);
        item.sold = true; 
        IERC721(item.nftContract).transferFrom(address(this), to, item.tokenId);
        marketItems[tokenId].owner = payable(to);
        emit Bought(address(item.nftContract), item.tokenId, item.price, item.seller, to);
Parent code: 
    function callPurchaseItem(
    uint256 tokenId,
    address tokenAddress
) public payable {
    LotteryEscrow(tokenAddress).purchaseItem{value: msg.value}(tokenId, msg.sender);

And here's the frontend code:

async function purchaseItem(tokenID, address) {
  const provider = new ethers.BrowserProvider(window.ethereum);
  const signer = await provider.getSigner();
  const lotteryContract = new ethers.Contract(
  try {
    // Convert totalPrice to BigNumber correctly
    const totalPrice = await lotteryContract.getTotalPrice(address, tokenID);
    const totalPriceString = totalPrice.toString();
    console.log(tokenID, address, totalPrice, "callPurchaseArguments");
    console.log(totalPriceString, "totalPriceString");  
    const feeData = await provider.getFeeData();

    // Access the relevant values:
    const gasPrice = feeData.gasPrice; 
    console.log("Gas price in gwei:", gasPriceInGwei);
   console.log("GasPrice", gasPrice);
    const purchaseItemTx = await lotteryContract.callPurchaseItem(tokenID, address, {
      value: totalPrice,
      // gasPrice: gasPrice, // Updated gas price
      // gasLimit: 12000000, // Adjust as needed

    const txReceipt = await purchaseItemTx.wait();
    // Check if the transaction was successful
    if (txReceipt && txReceipt.status === 1) {
      console.log("NFT purchased");
    } else {
      console.log("Transaction failed or was dropped");
  } catch (error) {
    console.error("Transaction submission failed:", error.message);

And I am attaching console values here as well

Can anyone tell me the reason behind this error?

Thank you!

You should specify which network you are trying to execute this transaction on.

On ethereum/mainnet, for example, the wallet above has no ether, which means that you must be attempting to execute this transaction on a different network; so which one is it?

It's polygon Mumbai network

The contract deployed at this address has no funds (zero balance):

Hence each one of the following two lines cannot complete successfully:

You probably need to send funds as part of your transaction, which is clearly missing it:

transaction = {
    "data": "0xee2729e500000000...",
    "from": "0xa5E4645137a9024bA06Ad7d65513E4a08cB9131f",
    "to": "0xAAEB20aD80ad21daC9F83B463c5d2Fe72B38e01e"

You can specify the amount of funds that you wish to pass by adding the value attribute:

transaction = {
    "data": "...",
    "from": "...",
    "to": "...",
    "value": "maticAmount"

Of course, your wallet needs to hold that amount plus the amount required for paying the gas.

But I have added value in the contract function and frontend as well.

LotteryEscrow(tokenAddress).purchaseItem{value: msg.value}(tokenId, msg.sender);

const purchaseItemTx = await lotteryContract.callPurchaseItem(tokenID, address, {
      value: totalPrice,

And I am getting the right value of totalPrice in console log

These transactions just keep failing if I add gasPrice and gasLimit manually and the value is already passed in the function so what is the reason behind this?

This clearly indicates that no funds were sent (no value attribute was specified).

Tell you what - if you verify this contract, then polygonscan should be able to display the exact error-message and not just Warning! Error encountered during contract execution [execution reverted].

Also note that this type of setting is relevant to transaction type 1, which you should probably specify explicitly as part of your transaction, otherwise it uses transaction type 2 (EIP 1559), where the max fee and priority fee must be specified.

In this failed transaction, for example, type 2 was specified:


So you should either specify type 1 along with your desired gas price and gas limit, or type 2 along with your desired max fee and priority fee.

Okay, thank you for your time:)

1 Like