I've just started learning about Chainlink Upkeepers, I'm very new to this and not able to plan my approach how to begin with automating the concludeAuction() function below. The smart contract manages the data of auctions with auctionItemId and this is also used as an argument. A single auctionItemId can be allocated only ones to a single auction item. Also, auctionItemId are keys to a private mapping.

I want to automate the conclusion of auction when the condition:

require(block.timestamp > idToAuctionItem[auctionItemId].startTime + idToAuctionItem[auctionItemId].auctionDuration) becomes true i.e. when auction timer expires.

I'm not able to understand how to start approaching the solution in terms of checkData is concerned as the auctionItemId need to be looked after, maybe or maybe not. Below is the whole function code written by me, any help is much appreciated.

function concludeAuction(address nftContract, uint256 auctionItemId) public payable nonReentrant {
require(msg.sender == idToAuctionItem[auctionItemId].seller, "You're not the auction creator");
require(block.timestamp > idToAuctionItem[auctionItemId].startTime + idToAuctionItem[auctionItemId].auctionDuration, "Bidding period not yet over");
require(idToAuctionItem[auctionItemId].sold == false, "Auction already concluded or canceled");

uint settlementPrice = idToHighestBid[auctionItemId].bidAmount;
uint tokenId = idToAuctionItem[auctionItemId].tokenId;

NFT nft = NFT(nftContract);
address soulCreator = nft.getSoulCreator(tokenId);
uint royalty = nft.getRoyalty(tokenId);

// 2.5% commission cut & royalty
uint _commissionValue = settlementPrice / 40 ;
uint _royalty = (settlementPrice * royalty) / 100 ;
uint _sellerValue = settlementPrice - _commissionValue - _royalty ;

owner.transfer(_commissionValue); // put commission account address in place of 'owner' in case different account needed for platform tax
IERC721(nftContract).transferFrom(address(this), idToHighestBid[auctionItemId].bidder, tokenId);

idToAuctionItem[auctionItemId].owner = payable(idToHighestBid[auctionItemId].bidder);
idToAuctionItem[auctionItemId].sold = true;

1 Answer 1


As per the docs, you need to have a checkUpkeep and a performUpkeep function. Sounds like your performUpkeep function will just call your concludeAuction function, passing in the parameters in the byte array parameter. Then in your performUpkeep function you can strip out the parameters and then pass them into the call to concludeAuction

function performUpkeep(bytes calldata /* performData */) external override {
    //strip out address and auction ID from calldata here to pass into conccludeAuction below
    concludeAuction(nftContract, auctionId)

Then for your checkUpkeep function you need to have your condition in there to determine when/if the performUpkeep function should be executed. If you need to pass in a param like the auction ID, that can be passed into the checkData byte array, then converted/stripped out to a parameter

function checkUpkeep(bytes calldata checkData) public view returns(bool, bytes memory) {
  //convert checkData to your auctionItemId here
  return (block.timestamp > idToAuctionItem[auctionItemId].startTime + idToAuctionItem[auctionItemId].auctionDuration);
  • Thanks for detailed explanation. Appreciate it. I have one query about the checkUpkeep() function that you've described. What I understood is that to pass the checkData (i.e. the auctionItemId) as the bytes array of auctionItemId(s), I need to do that manually (on the off-chain/server-side code) because that bytes array will be dynamically adding the auctionItemId(s) in itself as the auctions are listed (as written in smart contract's logic), also there might be cases where multiple auctions need to be concluded. Would you suggest to do that off-chain or is there an on-chain way as well? Commented Jan 29, 2022 at 11:11

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.