0

I am trying to set up a marketplace where I will sell with my own erc20 token. But whenever the following function works, it returns this error to me on the client side.

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Error: Transaction reverted without a reason string", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9","value":{"type":"BigNumber","hex":"0x286a97f7e4d000"},"data":"0xa706ac210000000000000000000000005fc8d32690cc91d4c39d9d3abcbd16989f87570700000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a7640000","accessList":null}, error={"code":-32603,"message":"Internal JSON-RPC error.","data":{"code":-32603,"message":"Error: Transaction reverted without a reason string","data":{"message":"Error: Transaction reverted without a reason string","data":"0x"}},"stack":"{\n  \"code\": -32603,\n  \"message\": \"Internal JSON-RPC error.\",\n  \"data\": {\n    \"code\": -32603,\n    \"message\": \"Error: Transaction reverted without a reason string\",\n    \"data\": {\n      \"message\": \"Error: Transaction reverted without a reason string\",\n      \"data\": \"0x\"\n    }\n  },\n  \"stack\": \"Error: Internal JSON-RPC error.\\n    at new n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:308657)\\n    at a (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:311413)\\n    at Object.internal (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:312023)\\n    at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:12:100028)\\n    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:12:101060\\n    at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-4.js:17:42171\"\n}\n  at new n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:308657)\n  at a (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:311413)\n  at Object.internal (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-2.js:1:312023)\n  at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:12:100028)\n  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-1.js:12:101060\n  at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/common-4.js:17:42171"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.1)

What exactly is the error in this function? Where am I doing wrong? I approve from my ERC20 contract and there are enough allowances. This function works in remix but not in ether.js.

Market.sol

  function createVaultItem(address nftContract,uint256 tokenId,uint256 price) public payable nonReentrant {
    require(price > 0, "Price cannot be zero");
    require(msg.value == listingFee, "Price cannot be listing fee");
    require(mytoken.transferFrom(msg.sender,address(this), listingFee),"Something wrong...");
    _itemIds.increment();
    uint256 itemId = _itemIds.current();
    idToVaultItem[itemId] =  VaultItem(itemId,nftContract,tokenId,payable(msg.sender),payable(address(0)),price,false);
    IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);
    emit VaultItemCreated(itemId,nftContract,tokenId,msg.sender,address(0),price,false);
    }

Nft.sol

    function createNFT(string memory tokenURI) public returns (uint) {
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(msg.sender, newItemId);
        _setTokenURI(newItemId, tokenURI);
        setApprovalForAll(contractAddress, true);
        return newItemId;
    }

Client Side | Ether.js

    async function createNFT(url) {
        let amount = 900000000000;
        const web3Modal = new Web3Modal()
        const connection = await web3Modal.connect()
        const provider = new ethers.providers.Web3Provider(connection)
        const signer = provider.getSigner()
        let cosmeta = new ethers.Contract(hhtoken,Token,signer)
        await cosmeta.approve(hhmarket,amount)
        let contract = new ethers.Contract(hhnft, NFT, signer)
        let transaction = await contract.createNFT(url)
        let tx = await transaction.wait()
        let event = tx.events[0]
        let value = event.args[2]
        let tokenId = value.toNumber()
        const price = ethers.utils.parseUnits(formInput.price, 'ether')
        contract = new ethers.Contract(hhmarket, Market, signer)
        let listingFee = await contract.getListingFee()
        //listingFee = listingFee.toString()
        transaction = await contract.createVaultItem(hhnft, tokenId, price, { value: listingFee })
        await transaction.wait()
        router.push('/')
    }
1
  • Why is msg.value == listingFee required when the fee is paid with a token?
    – Ismael
    Nov 2 at 5:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.