How to transfer buyer address list from ERC721 contract to external contract in Solidity?

Need help with contract communication

I’m working on a basic ERC721 token contract and I need to collect all the minter addresses into an array. Then I want to send this data to a different contract so I can use those addresses later for other functions.

I’m pretty new to blockchain development so any simple explanation would be great!

Here’s my current token contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract DigitalArt is ERC721 {
    string public constant METADATA_URL = "ipfs://...";
    uint256 private currentTokenId;
    
    constructor() ERC721("DigitalArt", "DART") {
        currentTokenId = 0;
    }
    
    function createToken() public {
        currentTokenId += 1;
        _safeMint(msg.sender, currentTokenId);
    }
    
    function tokenURI(uint256 id) public view override returns (string memory) {
        return METADATA_URL;
    }
    
    function getCurrentId() public view returns (uint256) {
        return currentTokenId;
    }
}

I tried making some getter functions but couldn’t figure out how to store the minter addresses properly. Also attempted to import this contract into another one but made a mess of it.

Any guidance on the best approach would be awesome!

Hey Ray84! I’ve been dealing with this exact problem recently. Quick question - do you want unique minter addresses only, or every mint event even if someone mints multiple times?

What’s your use case? What functions will the external contract run with these addresses? That’ll help determine the best approach.

I’m thinking you could add a mapping and array to track minters: mapping(address => bool) public hasMinted to avoid duplicates and address[] public minters for the list. My concern is gas costs as the array grows - have you thought about that?

Also, do you need to push data automatically on each mint, or should the external contract pull data when needed? Pull might be more gas efficient.

How are you handling storage costs as more people mint? Do you need real-time updates or can you batch them?

Tell me more about your specific requirements and I can help brainstorm a cleaner solution!

To transfer the addresses of minters, first, you should modify your ERC721 contract to keep track of them. You can create an array address[] public minters and a mapping mapping(address => bool) internal hasMinted to ensure uniqueness. In the createToken function, check if the sender’s address has already minted an NFT; if not, add it to the minters array. Additionally, expose a function getAllMinters that returns the array of minters to allow your external contract to access this data. This approach maintains a clear record of unique addresses while enabling efficient access.