Is there any ways to get a percentage fee when user sold their NFTs though my NFT platform?
I create a smart contract with ERC1155.
It allows users to create and mint their own NFTs.
After user mint, the user can post their NFTs on Rarible. They can sell their NFTs.
I’m planning to get a percentage fee when the NFT is sold.
Maybe the fee goes to the contract. And sometime I need to execute withdraw()
to get the balance of the contract (= fees) .
My question is How can I write the percentage fee into my smart contract?
Should I overwrite transfer
or something?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract NFTCryplo is ERC1155, Ownable {
mapping(uint256 => address) private minters;
constructor() ERC1155(""){}
function mint(address account,uint256 id,uint256 amount) public {
require(minters[id] == address(0) || minters[id] == msg.sender);
if(minters[id] == address(0)) {
minters[id] = msg.sender;
}
_mint(account,id,amount,"");
}
function uri(uint256 _id) override public pure returns (string memory) {
return string(
abi.encodePacked(
"https://example.com/nft/metadatas/",
Strings.toString(_id)
)
);
}
function withdraw() onlyOwner public payable {
payable(msg.sender).transfer(address(this).balance);
}
}