-3

I am building an NFT contract (ERC-721) on the Ethereum blockchain, I need to set up a fixed or percentage fee on each transfer/selling of NFT. Please guide

  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 22 '22 at 06:51

1 Answers1

1

In ERC721, there are 3 methods that provide NFT transfer:

function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;

Simply, what you would want to do is handle fees in the above methods. The most simplistic approach would be to collect the fee from caller, since all 3 methods are payable.

uint256 fee = 0.1 ether;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable{
    require(msg.value >= fee, "sent ether is lower than fee")
    // your erc721 implementation
}
keser
  • 2,472
  • 1
  • 12
  • 38
  • It seems we just need to override `transferFrom` as `safeTransferFrom` ends up calling `transferFrom`. Ref: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol#L163 – Ayudh Aug 24 '23 at 06:55