I'm trying to create a smart contract for raffling a NFT between users. Whenever an user tries create a raffle they need to specify the tokenContract
which is the contract address of the NFT, and the tokenId
which will be the corresponding id. I'm using a simple minting contract to simulate sending a token to the contract. However, when sending the raffle contract the minted token, and having onERC721Received
set up, the State
doesn't get changed to 1
.
According to etherscan the raffle contract did successfully receive the ERC721 token.
Relevant part of raffle contract:
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
...
contract Raffle is VRFConsumerBase, IERC721Receiver {
enum State {
Pending,
Active,
Calculating,
Finished
}
State public state;
...
...
function onERC721Received(address, address, uint256, bytes calldata) external override returns (bytes4) {
state = State.Active;
return IERC721Receiver.onERC721Received.selector;
}
Minting contract:
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TestToken is ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("TestToken", "TST") {}
function mintNFT(address recipient)
public onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
return newItemId;
}
}