DevABDee
DevABDee

Reputation: 180

How to Transfer NFTs using Chainlink's Automation/Keeper (checkUpkeep & performUpKeep)

I'm working on an NFT Auction contract. I'm trying to achieve 1. NFT transfer to the highest bidder. 2. highest bidder's bid value to the prev NFT owner or Auction creator. 3. A small platform cut sent to the contract's owner.

All this is working smoothly when I'm doing things manually. But when I'm trying to achieve this using chainlink automation, It fails.

From my understanding, It is failing because of the allowance issue. My Qs is, is it even possible to achieve this using chainlink automation? if yes, then how?

When the NFT owner, lists his NFT for Auction, he is giving NFT transfer allowance to the contract address.

    function checkUpkeep(bytes calldata /* checkData */) external view override returns(bool upkeepNeeded, bytes memory performData) {
        for(uint i=0; i < auctionIDs.length; i++){
            if(auctions[auctionIDs[i]].endTime != 0 && block.timestamp > auctions[auctionIDs[i]].endTime){
                upkeepNeeded = true;
                performData = abi.encodePacked(uint256(auctionIDs[i]));
            }
        }
        return (upkeepNeeded, performData);
    }

    function performUpkeep(bytes calldata performData) external override nonReentrant {
        uint256 auction_id = abi.decode(performData, (uint256));

        if(auctions[auction_id].endTime != 0 && block.timestamp > auctions[auction_id].endTime){

            auctions[auction_id].listed = false;

            safeTransferFrom(podcastId[auctions[auction_id].podcastId].nftOwner, bidders[auction_id].highestBidder, podcastId[auctions[auction_id].podcastId].tokenId);

            uint256 platformCut = (platformFee * bidders[auction_id].highestBid)/100;
            uint256 NftOwnerCut = bidders[auction_id].highestBid - platformCut;

            (bool pass, ) = platformFeeRecipient.call{value: platformCut}("");
            require(pass, "platformFee Transfer failed");
            (bool success, ) = (podcastId[auctions[auction_id].podcastId].nftOwner).call{value: NftOwnerCut}("");
            require(success, "NftOwnerCut Transfer Failed");

            podcastId[auctions[auction_id].podcastId].nftOwner = bidders[auction_id].highestBidder;
            emit AuctionResulted(auction_id, bidders[auction_id].highestBidder, bidders[auction_id].highestBid);
            bidders[auction_id].highestBid = 0;
            auctions[auction_id].endTime = 0;
            
        }

    }

Full Code/Contracts: https://mumbai.polygonscan.com/address/0x7e2DA19C130cb3B483FA7f17C45c70716ABF5Fe8

Chainlink upKeep: https://automation.chain.link/mumbai/21891159634677518530356555981285976030474691922841692133624884405593696766700

Pls help, Thanks.

Upvotes: -2

Views: 84

Answers (1)

Richard G
Richard G

Reputation: 308

I believe the issue is that your upkeepNeeded is returning false due to the auction end time being 0

 if(auctions[auctionIDs[i]].endTime != 0

enter image description here

Upvotes: 0

Related Questions