如何在NFT征收中增加版税



我目前正在学习有关nft的知识,并且我已经达到了部署合同的地步,我可以薄荷,一切都很顺利。唯一缺少的部分是我的艺术作品的版税。我看到了两个方法:

  • 向智能合约添加特许权使用费(我不确定如何做到这一点)
  • 管理公海特许权使用费

谁能给我指路?不确定哪种方法是最好的,更安全…我在Rinkeby测试网络上运行,所以我可以尽可能多地修改合同以进行测试。这是我现在的合同:


pragma solidity >=0.8.9 <0.9.0;
import 'erc721a/contracts/ERC721A.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/cryptography/MerkleProof.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
contract FalconContract is ERC721A, Ownable, ReentrancyGuard {
using Strings for uint256;
bytes32 public merkleRoot;
mapping(address => bool) public whitelistClaimed;
string public uriPrefix = '';
string public uriSuffix = '.json';
string public hiddenMetadataUri;

uint256 public cost;
uint256 public maxSupply;
uint256 public maxMintAmountPerTx;
bool public paused = true;
bool public whitelistMintEnabled = false;
bool public revealed = false;
constructor(
string memory _tokenName,
string memory _tokenSymbol,
uint256 _cost,
uint256 _maxSupply,
uint256 _maxMintAmountPerTx,
string memory _hiddenMetadataUri
) ERC721A(_tokenName, _tokenSymbol) {
setCost(_cost);
maxSupply = _maxSupply;
setMaxMintAmountPerTx(_maxMintAmountPerTx);
setHiddenMetadataUri(_hiddenMetadataUri);
}
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
_;
}
modifier mintPriceCompliance(uint256 _mintAmount) {
require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
_;
}
function whitelistMint(uint256 _mintAmount, bytes32[] calldata _merkleProof) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
// Verify whitelist requirements
require(whitelistMintEnabled, 'The whitelist sale is not enabled!');
require(!whitelistClaimed[_msgSender()], 'Address already claimed!');
bytes32 leaf = keccak256(abi.encodePacked(_msgSender()));
require(MerkleProof.verify(_merkleProof, merkleRoot, leaf), 'Invalid proof!');
whitelistClaimed[_msgSender()] = true;
_safeMint(_msgSender(), _mintAmount);
}
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) mintPriceCompliance(_mintAmount) {
require(!paused, 'The contract is paused!');
_safeMint(_msgSender(), _mintAmount);
payable(owner()).transfer(msg.value);
}

function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner {
_safeMint(_receiver, _mintAmount);
}
function walletOfOwner(address _owner) public view returns (uint256[] memory) {
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
uint256 currentTokenId = _startTokenId();
uint256 ownedTokenIndex = 0;
address latestOwnerAddress;
while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) {
TokenOwnership memory ownership = _ownerships[currentTokenId];
if (!ownership.burned && ownership.addr != address(0)) {
latestOwnerAddress = ownership.addr;
}
if (latestOwnerAddress == _owner) {
ownedTokenIds[ownedTokenIndex] = currentTokenId;
ownedTokenIndex++;
}
currentTokenId++;
}
return ownedTokenIds;
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
if (revealed == false) {
return hiddenMetadataUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
: '';
}
function setRevealed(bool _state) public onlyOwner {
revealed = _state;
}
function setCost(uint256 _cost) public onlyOwner {
cost = _cost;
}
function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner {
maxMintAmountPerTx = _maxMintAmountPerTx;
}
function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner {
hiddenMetadataUri = _hiddenMetadataUri;
}
function setUriPrefix(string memory _uriPrefix) public onlyOwner {
uriPrefix = _uriPrefix;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
function setPaused(bool _state) public onlyOwner {
paused = _state;
}
function setMerkleRoot(bytes32 _merkleRoot) public onlyOwner {
merkleRoot = _merkleRoot;
}
function setWhitelistMintEnabled(bool _state) public onlyOwner {
whitelistMintEnabled = _state;
}
function withdraw() public onlyOwner nonReentrant {
(bool hs, ) = payable(0x81C3E1d02c6ad3A1E065193238B40aB0c8E12D9b).call{value: address(this).balance * 50 / 100}('');
require(hs);
// This will transfer the remaining contract balance to the owner.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
// =============================================================================
}
function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}
}

这是一个非常著名和研究过的用例。有一个EIP,您可以(并且应该)遵循它来获得最好的安全性和可操作性,更不用说您甚至不需要编写代码。公平地说,EIP不是ERC。这是一个社区请求,到写这个答案的时候,还没有得到以太坊的批准或正式支持

我建议阅读:https://eips.ethereum.org/EIPS/eip-2981

在这里你可以阅读一个示例实现:https://github.com/dievardump/EIP2981-implementation

燃气成本可能很高,所以要意识到这一点,也许你可以通过牺牲功能来减少一些地方。

相关内容

  • 没有找到相关文章