Transaction fee per buy

  1. for this code the itemsForSale[id].seller.transfer(msg.value); is the one sending the ETH to the seller right? if I were to add
uint256 OwnerAddress = "0x12313..."
OwnerAddress.transfer(msg.value) will it be consider as transaction fee?
function buyItem(uint256 id) payable external ItemExists(id) IsForSale(id) HasTransferApproval(itemsForSale[id].tokenAddress, itemsForSale[id].tokenId){
        require(msg.value >= itemsForSale[id].askingPrice, "Insufficient Funds");
        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);

        emit itemSold(id, msg.sender, itemsForSale[id].askingPrice);

is there any moralis tutorial for transaction fees?

what you mean by a transaction fee? you are referring to the gas fee or to something else?

Transaction fee for using the marketplace.

Iā€™m thinking inside the buyItem i add OwnerAddress our metamask wallet address where the transaction fee per buy is sent

uint256 OwnerAddress = "0x12313..."

ok, so you mean like a transaction fee of 1% of the price that would go to the marketplace address and the rest of 99% to the seller?

yes something like that, the 1% would go directly to our wallet (creator) of the NFT marketplace

you should somehow change this line:


in a transfer that is equal to 99% for msg.value, assuming that the rest of 1% will remain in the marketplace smart contract account

but should I add this as well beside that? To transfer the wallet we shared in the company

uint256 OwnerAddress = ā€œ0x12313ā€¦ā€

you may want to make that transfer from time to time in order to save some transaction fees, but you could do it that way too

Thank you! but defining it within, and adding .transfer will send it right?

you may need to use a different syntax like: address payable OwnerAddress = ā€œ0x12313ā€¦ā€, but it should work in theory.

Thanks this make sense!

one last thing

is the emit what triggers the metamask or transaction right or the function itself?

emit itemSold(id, msg.sender, itemsForSale[id].askingPrice);

That emit in only an event that it is easily parsed in order to be able to know what happened in a transaction, the transaction would work without that emitted event too, but it is easier to process events, for example in order to sync events in your Moralis database, the transaction would have to emit those events.

1 Like

Thank you! This all make sense now. Thanks @cryptokid