yo, i’ve run into this before. the issue is probably in how ur handling the commission. instead of passing it as a parameter, calculate it in the contract.
try something like this in ur contract:
function sellNFT(address nftContract, uint256 itemId) public payable {
uint256 price = listedItems[itemId].price;
uint256 commission = price * 25 / 1000; // 2.5% fee
require(msg.value == price + commission, "Wrong amount sent");
// rest of ur logic here
}
hey there ethan_witty! i’ve been tinkering with nft marketplaces too and ran into similar commission headaches. have you considered calculating the fee inside the contract instead of passing it as a parameter? that way you can make sure everything adds up correctly.
here’s a quick idea:
function sellNFT(address nftContract, uint256 itemId) public payable {
uint256 price = listedItems[itemId].price;
uint256 commission = (price * 25) / 1000; // 2.5% commission
require(msg.value >= price + commission, "not enough eth sent");
// transfer price to seller, commission to contract owner
listedItems[itemId].seller.transfer(price);
payable(owner).transfer(commission);
// rest of your logic here...
}
then in your js, you’d just need to send the total amount:
I’ve dealt with a similar issue in my NFT marketplace project. The problem is likely in how you’re handling the commission calculation and transfer. Instead of passing the fee as a parameter, calculate it within the smart contract itself. This ensures consistency and prevents potential manipulation.
Try modifying your sellNFT function like this:
function sellNFT(address nftContract, uint256 itemId) public payable {
uint256 price = listedItems[itemId].price;
uint256 commission = price * 25 / 1000; // 2.5% fee
require(msg.value == price + commission, "Incorrect amount sent");
listedItems[itemId].seller.transfer(price);
payable(owner).transfer(commission);
// Rest of your function logic...
}