ERC721 Staking Contract - Allow to stake only certain tokensID

Hello everyone, I'm using this code to create a staking contract for my NFT collection.
I would like to create a function that restricts staking only to certain tokensId.
Which kind of function could I use? Thanks in advance to everyone

You can call stake(_tokenIds) to stake some NFTs, but if you want to do some limitation about the token id, I think you have got to update the code to check if the token id is valid or not.

You could use a require statement that checks the tokenId and using a mapping uint256 => bool you trace the ids that can be staken or not

1 Like

I think using require and mapping could be a solution. Could you please help me with a draft of that function? It would be amazing

Sure!

mapping(uint256 => bool) public canStake;

function setCanStake(uint256 id, bool status) external onlyOwner{
  canStake[id] = status;
}

function stake(uint256 tokenId) external {
  require(canStake[tokenId], "Can't stake");
  ...
}
2 Likes

Thank you! It is super helpful!

1 Like