Warning! Error encountered during contract execution [Reverted]

I m trying to Fix this issue !

Warning! Error encountered during contract execution [Reverted]


Please any one help me fix this


Please could you provide us with your contract code and also describe what function you were trying to call in these transactions. It will be quicker for both of us if we are on the same page.


am following the tutorial but using Reactjs… and much completed just getting the error in buying nfts… when meta mask popup is opening it is showing transaction error : exception thrown in contract code

after confirming the transaction , item is removed from EthNFTOwners but not from the EthNFTTransfers… and also i am not getting what is EthNFTTransfers if somebody clear my concept…will be grateful for that as I didn’t know anything about blockchain before landing on this project…

console logging this error after completing the transaction

this is contract code…

//Contract based on https://docs.openzeppelin.com/contracts/3.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract Marketplace {
    struct ProductItem{
        uint256 id;
        address tokenAddress;
        uint256 tokenId;
        address payable seller;
        uint256 price;
        bool purchased;
    ProductItem[] public products;

    mapping(address => mapping(uint => bool)) activeItems;

    event productCreated(uint256 id, uint256 tokenId, address tokenAddress, uint256 price);
    event productSold(uint256 id, address buyer, uint256 price);

    modifier OnlyItemOwner(address tokenAddress, uint256 tokenId){
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.ownerOf(tokenId) == msg.sender);

    modifier HasTransferApproval(address tokenAddress, uint256 tokenId){
        IERC721 tokenContract = IERC721(tokenAddress);
        require(tokenContract.getApproved(tokenId) == address(this));

    modifier ItemExists(uint256 id){
        require(id < products.length && products[id].id == id, "Could not find Item");

    modifier IsForSale(uint256 id){
        require(products[id].purchased == false, "Item is already sold");

    function itemAdded(uint256 tokenId, address tokenAddress, uint256 price) OnlyItemOwner(tokenAddress, tokenId) HasTransferApproval(tokenAddress, tokenId) external returns (uint256){
        require(activeItems[tokenAddress][tokenId] == false, "Item is already up for sale");
        uint256 newItemId = products.length;
        products.push(ProductItem(newItemId, tokenAddress, tokenId, payable (msg.sender), price, false));
        activeItems[tokenAddress][tokenId] = true;

        assert(products[newItemId].id == newItemId);
        emit productCreated(newItemId, tokenId, tokenAddress, price);
        return newItemId;

    function buyItem(uint256 id) payable external ItemExists(id) IsForSale(id) HasTransferApproval(products[id].tokenAddress, products[id].tokenId){
        require(msg.value >= products[id].price, "Not enough Funds sent");
        require(msg.sender != products[id].seller);

        products[id].purchased = true;
        activeItems[products[id].tokenAddress][products[id].tokenId] = false;
        IERC721(products[id].tokenAddress).safeTransferFrom(products[id].seller, msg.sender, products[id].tokenId);

        emit productSold(id, msg.sender , products[id].price);


and this is buy function

export const buyItems = async (tokenId,price) => {
    try {

        const web3 = await Moralis.Web3.enable();

        const currentUser = await Moralis.User.current();
        const userAddress = currentUser.get('ethAddress')

        const priceInWei = web3.utils.toWei(price,'ether')

        window.marketplaceContract = new web3.eth.Contract(marketplaceABI, marketplaceRemixAddress);
        const transfer = await window.marketplaceContract.methods.buyItem(tokenId).send({from:userAddress, value:priceInWei})

    } catch (error) {


Most likely than not, one of your require statements are getting hit thus reverting your transaction. Since the transaction revert did not have a message attached to it, I’m guessing the require statement that is getting hit is –

Perhaps you can put a message near the require statement and see if that gets returned to confirm it –

require(msg.sender != products[id].seller, "This is a test require statement message");

To resolve this make sure to not buy the NFT item from the same address as you’re using to sell it.

Hope this helps.

Also, please make sure to test the contract locally on ganache (or remix) before you deploy on the test network. It’s easier to debug in those scenarios.


1 Like

okay i will try this and let you know ! about the Progress! :slight_smile:

Hi am currently confronted with similar challenge and don’t know how to find my way around it.

However, mine is on BSC.

Pls, I am open to our advice on how to recover the money.

we are going to need to know more info about your situation

i have a similar situation in the bsc, yesterday i bought a bond in a defi 2.0 platform but i received this message and the fund doens´t appear, loooks like the funds send to the contract but gave me this issue and the funds doens´t appear reverted,

if the transaction reverted, then the funds shouldn’t be lost, it if was only one transaction done

but the funds not appear, 17 hours ago i did the transaction

this is the message

already see in bsc scan in my wallet and doesn´t appear the funds reverted, is weird

how did the funds get transferred from your wallet? did you call approve?

yes i did the approve from de contrat, it was in nemesis dao, i bought a bond transfering busd to the contract, so the transaction fails and gave me this message, transaction reverted but 20 hours after and the funds doesn´t reverted.

You usually don’t send busd in that transaction, are you sure that is the transaction that transferred busd from your address?

yes, all is ok already reverted the transaction and the funds appear in my wallet only 23 hours :slight_smile:

I’m getting the same message on bsc, transaction reverted.
This is when trying to enable a token so I can sell it.

Error encountered during contract execution [execution reverted]

it doesn’t say too much, there was some error on execution somewhere, and it looks like it wasn’t in a require statement

No it doesn’t. IDK what actions to take to find out why I can’t even enable it, never mind sell it…