APE Price: $0.72 (-4.12%)

Contract Diff Checker

Contract Name:
BatchTransfer

Contract Source Code:

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

interface IERC721 {
    function setApprovalForAll(address operator, bool approved) external;
    function safeTransferFrom(address from, address to, uint256 tokenId) external;
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

contract BatchTransfer {
    address public nftContract;

    // Constructor to set the NFT contract address
    constructor(address _nftContract) {
        nftContract = _nftContract;
    }

    // Function for the owner to set approval for the batch transfer contract on the NFT contract
    function approveBatchTransferContract() external {
        IERC721(nftContract).setApprovalForAll(address(this), true);
    }

    // Function to batch transfer ERC721 tokens from a single owner to a recipient
    function batchTransfer(
        address from,
        address to,
        uint256[] calldata tokenIds
    ) external {
        require(tokenIds.length > 0, "No tokens provided for transfer");

        // Ensure that the contract is approved to transfer tokens
        require(IERC721(nftContract).isApprovedForAll(from, address(this)), "Contract not approved for transfer");

        for (uint256 i = 0; i < tokenIds.length; i++) {
            IERC721(nftContract).safeTransferFrom(from, to, tokenIds[i]);
        }
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):