1

Hello I have NFT Smart Contract and I need to distribute royalties. I found out that the Payment Splitter will be amazing for that scenario however I don't know all of the payees when NFT Smart Contract is initialized. I need to add the third payee member when he is minting the NFT but I can see the addPayee function is private, do you have any suggestion, how would you handle this case. There will be in total 3 payees addresses. 2 of them are known when the collection is created and the 3rd one is known when the nft is minted how to add this address to the payment splitter or some separate logic which will be helpful. In our int function we should be adding the 3rd payee address

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/finance/PaymentSplitter.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract Launchpad is ERC1155, Ownable, PaymentSplitter {
    using Counters for Counters.Counter;
    Counters.Counter private ID;

    string public name;
    string public symbol;

    uint256 public startingAt;

    // Mapping from token ID to token URI
    mapping(uint256 => string) private idToUri;

    // Mapping from token ID to max supply
    mapping(uint256 => uint256) private maxSupply;

    // Mapping from token ID to total supply
    mapping(uint256 => uint256) private totalSupply;

    constructor(
        string memory _uri,
        string memory _name,
        string memory _symbol,
        uint256 _startingAt,
        address[] memory _royalties,
        uint256[] memory _shares
    ) ERC1155(_uri) PaymentSplitter(_royalties, _shares) {
        name = _name;
        symbol = _symbol;
        startingAt = _startingAt;
    }

    function create(string calldata _cid, uint256 _maxSupply)
        external
        returns (uint256 _id)
    {
        require(_maxSupply > 0, "Max supply should be higher than 0");

        _id = _nextId();

        maxSupply[_id] = _maxSupply;
        totalSupply[_id] = 0;

        string memory _uri = _createUri(_cid);
        idToUri[_id] = _uri;

        _mint(msg.sender, _id, 0, "");

        emit URI(_uri, _id);
    }

    function mint(address _account, uint256 _id) public {
        require(_exists(_id), "Invalid id");
        require(
            totalSupply[_id] < maxSupply[_id],
            "No more available mints for this nft"
        );

        totalSupply[_id] = totalSupply[_id] + 1;

        new PaymentSplitter(_royalties, _shares);

        _mint(_account, _id, 1, "");
    }

    function _nextId() internal returns (uint256 id) {
        ID.increment();
        return ID.current();
    }

    function _exists(uint256 _id) internal view returns (bool) {
        return (bytes(idToUri[_id]).length > 0);
    }

    function _createUri(string memory _cid)
        internal
        view
        returns (string memory _uri)
    {
        string memory baseUri = super.uri(0);
        return string(abi.encodePacked(baseUri, _cid));
    }

    function uri(uint256 _id) public view override returns (string memory) {
        return idToUri[_id];
    }
}

2
  • What's the motivation for adding a 3rd payee? Can that person not tell you their address ahead of time? Or, are you going to want to add another payee to your payment splitter every time you mint?
    – Civilian
    Nov 5, 2021 at 23:39
  • @andon did you ever solve this?
    – jasan
    Jul 28, 2022 at 10:55

1 Answer 1

1

Dont use the PaymentSplitter Contract directly. Instead write your your Contract inheriting from the PaymentSplitter contract and use that.

eg. contract MyPaymentSplitter is PaymentSplitter {...}

contract Launchpad is ERC1155, Ownable, MyPaymentSplitter { ... }

In the MyPaymentSplitter contract, you can add your own functionality to add/remove payees.

1
  • I don't see how this suggestion is different from what the OP is doing. They're already inheriting the PaymentSplitter contract, and you suggested to inherit it twice which is cleaner, but the problem of overriding that specific private _addPayee function remains
    – wongx
    May 5, 2022 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.