1

I am trying to create an NFT auction and can currently receive ERC721 to my contract.

Im running into a roadblock however. Im wondering how to transfer all these NFTs to their proper winners at once rather than manually approving a group of contracts.

    function approveWinners() external {
        address[] memory _winners = cManager.getWinners();

        for (uint256 i = 0; i < nftContractList.length; i++) {
            approver(
                nftContractList[i],
                _winners[i],
                nftToId[nftContractList[i]]
            );

        }
    }

    function approver(
        address _nftContract,
        address _recipient,
        uint256 _tokenId
    ) internal {
        IERC721(_nftContract).approve(_recipient, _tokenId);
    }

    function withdrawNFT() external payable {
        address[] memory _winners = campaignManager.getWinners();

        // organizeNFTByFloor();
        for (uint256 i = 0; i < nftContractList.length; i++) {
            IERC721(nftContractList[i]).safeTransferFrom(
                msg.sender,
                _winners[i],
                nftToId[nftContractList[i]]
            );
        }
    }

When I execute I receive Error: Transaction reverted: function returned an unexpected amount of data

Is there any reliable way I can transfer multiple NFTs at once to various addresses. Ideally I'd like to get it down to 2 transactions, one to approve each NFT to its respective owner and the other to actually handle the safeTransferFrom()

5
  • Is there a contract between the winners? What does approver do? Does it approves the recipients? You shouldn't need to approve recipients. The NFT's owner should approve the contract that has the withdrawNFT function.
    – Ismael
    Feb 20, 2022 at 4:52
  • The contract will own the NFTs. I figured approver could be called to approve those transfers, but the msg.sender probably wont be the contract so that wont work. Ideally at the end of this auction I want some service like chainlink keepers or gelato to execute a function that will transfer all NFTs to their proper recipients. Would it be better to use transferFrom in this case?
    – 0xNotes
    Feb 20, 2022 at 4:59
  • If the contract that has the function withdrawNFT owns the tokens then you don't need to call approve.
    – Ismael
    Feb 20, 2022 at 5:01
  • Excellent. Will give it a try.
    – 0xNotes
    Feb 20, 2022 at 5:03
  • This is not quite the solution still working on it.
    – 0xNotes
    Feb 22, 2022 at 6:00

2 Answers 2

0

The way I did it is to create a function that uses a for loop to go through each NFT for transfer one by one.

Can't find a better solution so far. Would be happy to accept any better suggestion than this one.

  mintBatch(
        uint256 number,
        string memory nonce,
        bytes32 hash,
        bytes memory signature,
        uint256[] memory nftIds,
        uint256 typeId,
        address to
    ) external payable {
        // The verification part is ignored as it is irrelevant to this question
        for (uint256 i = 0; i < number; ++i) {
            _mintHandler(nftIds[i], to);
        }
    }

0

I made a small (free) tool that helps when transferring multiple NFTs from an ERC721: https://theforever.io/erc721-batch-transfer-tool

When airdropping, you can airdrop to a single wallet and then transfer them out from there.

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.