Function for buying NFT

function buy(address nftContract, uint256 itemId)
    uint256 price = idToMarketItem[itemId].price;
    uint256 tokenId = idToMarketItem[itemId].tokenId;
        msg.value >= price,
        "Please submit the asking price in order to complete the purchase"

    fandomToken(nftContract).transfer(msg.sender, tokenId, 1);
    idToMarketItem[itemId].owner = payable(msg.sender);
    idToMarketItem[itemId].sold = true;

Test case for the above code

describe('buy', async() => {
    it('buy functionality check ', async()=>{
        const nftContract = '0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0'
        console.log("ACCOUNT 2",accounts[2])
        const result_nftContract = await contract_nFTMarket.buy(nftContract,1, {from: accounts[0],Value: 2000000000000000000})
        const eventMinted = await result_nftContract.logs[0].args
        // assert.equal(eventMinted.category,'video')
        // assert.equal(eventMinted.nftContract,contract_address)

but still, I am getting below error

**Error: Returned error: VM Exception while processing transaction: revert Please submit the asking price in order to complete the purchase -- Reason given: Please submit the asking price in order to complete the purchase. **

  • 1
    Caculate and check the price before calling the buyFunction, your price is less than the 2ETH Commented Jan 25, 2022 at 6:28

1 Answer 1


I think error is here:

{from: accounts[0],Value: 2000000000000000000})

Value is capital letter. should be {value: 2000000000000000000})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.