ERC-721, Setup developer fees on each transfer

460 views Asked by At

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

There are 1 answers

1
keser On

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
}