buyItem = async (item) => {
user = await Moralis.User.current();
if (!user){
login();
return;
}
console.log(item.askingPrice);
await marketplaceContract.methods.buyItem(item.uid).send({from: user.get('ethAddress'), value: item.askingPrice});
}
this is my buy function item.askingPrice is returning perfect asking value but in metamask, it's not getting added. When I try to tap on buy metamask is only asking for gas price.
It should be like asking price + gas fee but in my case, it's only asking for gas price
please help.
hey can you help me this my smart contract function so I publish buy function from js and smart contract also so please can you help
function buyItem(uint256 id) payable external ItemExists(id) IsForSale(id) HasTransferApproval(itemsForSale[id].tokenAddress,itemsForSale[id].tokenId){
require(msg.value >= itemsForSale[id].askingPrice, "Not enough funds sent");
require(msg.sender != itemsForSale[id].seller);
itemsForSale[id].isSold = true;
activeItems[itemsForSale[id].tokenAddress][itemsForSale[id].tokenId] = false;
IERC721(itemsForSale[id].tokenAddress).safeTransferFrom(itemsForSale[id].seller, msg.sender, itemsForSale[id].tokenId);
itemsForSale[id].seller.transfer(msg.value);
emit itemSold(id, msg.sender,itemsForSale[id].askingPrice);
}
it looks like this function has only one parameter of type uint256, it should be easy to use Moralis.executeFunction as mentioned in the above post
Are you populating msgValue when you call buyItem?
Here is the specific example from the Moralis documentation: