pragma solidity 0.6.6;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract AdvancedCollectible is ERC721, VRFConsumerBase {

    bytes32 internal keyHash;
    uint256 public fee;
    uint256 public tokenCounter;
    enum Color{BROWN, RED, BLUE}

    mapping(bytes32 => address) public requestIdToSender;
    mapping(bytes32 => string) public requestIdToTokenURI;
    mapping(uint256 => Color) public tokenIdToColor;
    mapping(bytes32 => uint256) public requestIdToTokenId;
    event requestedCollectible(bytes32 indexed requestId);

    constructor(address _VRFCoordinator, address _LinkToken, bytes32 _Keyhash) public
    VRFConsumerBase(_VRFCoordinator, _LinkToken)
    ERC721("Doggie", "DOG")
       keyHash = _keyhash;
       fee = 0.1 ** 18; // 0.1 LINK 
       tokenCounter = 0;
    function createCollectible(uint256 userProvidedSeed, string memory tokenURI) 
    public returns (bytes32){
        bytes32 requestId = requestRandomness(KeyHash, Fee, user);
        requestIdToSender[requestId] = msg.sender;
        requestIdToTokenURI[requestId] = tokenURI;
        emit requestedCollectible(requestID);

    function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override {
        address dogOwner = requestIdToSender[requestId];
        string memory tokenURI = requestIdToTokenUri[requestId];
        uint256 newItemId = tokenCounter;
        _safeMint(dogOwner, newItemId);
        _setTokenURI(newItemId, tokenURI);
        Color apecolor = Color(randomNumber % 3);
        tokenIdToColor[newItemId] = apecolor
        requestIdToTokenId[requestId] = newItemId;
        tokenCounter = tokenCounter + 1;

    function setTokenURI(uint256 tokenId, string memory _tokenURI) public {
            _isApprovedOrOwner(msgSender)(), tokenId),
            "ERC721: transfer caller is not owner nor approved"
        _setTokenURI(tokeId, _TokenURI)
  • Do you have the rest of the conntract? It is missing the contract name, imports, and variable declarations. I'd guess the problem is in line 38 but can't test with much of the code missing.
    – Ismael
    Aug 4 at 4:00
  • Hey, I already added the rest of the contract, can you please check, thankyou Aug 4 at 6:26
  • The code has several basic errors: 1/ there are several uppercase vs lowercase, 2/ in createCollectible there's an extra {, 3/ in setTokenURI probably you wanted to use require instead of returns, 4/ the operation 0.1 ** 18 in the constructor fails, perhaps you wanted to write 0.1 * 10**18. There are a few other but I suggest to start by the above ones.
    – Ismael
    Aug 4 at 7:14
  • Thank you for help, I already corrected the mistakes mentioned above but I still get the same error when compiling, contracts/AdvancedCollectible.sol:38:14: ParserError: Expected '(' but got identifier function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override { Aug 4 at 7:36
  • 1
    Hey, thank you for your help sir, I already solve this error I guess it's just basic errors and some typos, thank you so much for your time. Aug 4 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.