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];
require(
msg.value >= _totalPrice,
"not enough matic to cover item price and market fee"
);
require(!item.sold, "item already sold");
item.seller.transfer(item.price);
feeAccount.transfer(_totalPrice - item.price);
item.sold = true;
IERC721(item.nftContract).transferFrom(address(this), to, item.tokenId);
marketItems[tokenId].owner = payable(to);
allSoldItems.push(tokenId);
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(
LotteryEscrowParentContract,
lotteryEscrowParentABI,
signer
);
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!