0

I am calling the following function from a front-end on a Solidity smart contract, but it is not transferring the price and commission amounts properly with the call functions, although the ownership of the token is transferred correctly using the safeTransferFrom function. How can I transfer the amounts?

 function tokTransfer(address payable from, address to, uint256 tokenId, uint256 price, uint256 commission) payable external {
    
    (bool success, ) = from.call{value: price}('');
    require(success, "Transfer failed.");
    (success, ) = address(this).call{value: commission}('');
    require(success, "Transfer failed.");

    this.safeTransferFrom(from, to, tokenId);
 }

Thank you. J

10
  • This code doesn't make much sense address(this).call{value: commission} it is transfering commission to itself. If you have a receive or fallback function it should work in any case. Does the contract have a receive function?
    – Ismael
    Mar 2, 2021 at 2:57
  • Hi @Ismael. I could add one, but the issue is that the total amount sent is actually being transferred to the contract when executing the safeTransferFrom function, in exchange of the token ownership transfer. I would like to transfer the price to the seller (which has authorised the contract to sell his tokens) and only the commission to the contract (instead of the entire amount, as is the case now).
    – JF0001
    Mar 2, 2021 at 3:05
  • If msg.value = price + commission the transferring price to the seller should be enough, the comission is already in the contract. If the commission is included in the price you should transfer price - commission to the seller.
    – Ismael
    Mar 2, 2021 at 3:16
  • 1
    No, safeTransferFrom doesn't handle ethers. The code this.safeTransferFrom(seller, buyer, tokenId) makes this transfers tokenId from seller to buyer. It requires previous approval from seller to this. The ether should be in the contract since tokTransfer is payable, the buyer send ethers to the contract with the call to tokTransfer. I'm assuming the contracts have standard ERC721 behavior. Also it is kind a little odd that tokTransfer is in the ERC721 I'd use a separate contract.
    – Ismael
    Mar 4, 2021 at 4:06
  • 1
    It should work. It is subjective matter. If you want to validate that the buyer had sent ethers use require(msg.value >= price, "Not enough ether sent).
    – Ismael
    Mar 5, 2021 at 0:14

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.