Hey everyone, I am facing an error called:
"Transaction submission failed: Error: missing revert data (action="estimateGas", data=null, reason=null, transaction={ "data": "0x327249000000000000000000000000005d7e1d2cbcc0e13ebd0453152be36636d23f90500000000000000000000000000000000000000000000000000000000000000000", "from": "0x1a5516BeDB0CaAB297c8cecaBdFe96325469EF2d", "to": "0x8ffaee855F945aD8B7e9064F8A6A81c205DE24c4" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.4.0)
at makeError (webpack-internal:///(:3000/app-pages-browser)/./node_modules/ethers/lib.commonjs/utils/errors.js:121:21)
When calling purchaseItem function to buy an NFT in my NFT Marketplace.
Could you please check the below code?
address payable public feeAccount = payable(address(this)); // Sendig 2% fee to contract itself
uint256 public feePercent = 2;
function purchaseItem(address nftContract, uint256 tokenId) external payable nonReentrant{
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(nftContract).transferFrom(address(this), msg.sender, item.tokenId);
allSoldItems.push(tokenId);
emit Bought(item.itemId, nftContract, item.tokenId, item.price, item.seller,
msg.sender);
}
Frontend code:
async function purchaseItem(address, tokenID) {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const MarketpaceContract = new ethers.Contract(
MarketplaceContractAddress,
MarketplaceContractABI,
signer
);
try {
const totalPrice = await MarketpaceContract.getTotalPrice(tokenID);
console.log(tokenID, address, totalPrice, "callPurchaseArguments");
console.log(totalPrice,"value");
const purchaseItemTx = await MarketpaceContract.purchaseItem(address, tokenID, {
value: totalPrice,
});
const txReceipt = await purchaseItemTx.wait();
console.log(txReceipt, "txReceipt");
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);
console.log("Error code:", error.code);
console.log("Error data:", error.data);
if (error.transaction) {
console.log("Transaction data:", error.transaction);
}
}
}
I have attached a snapshot of the console value as well.
Thank you:)