PatrickAlphaC / hardhat-smartcontract-lottery-fcc

MIT License
117 stars 182 forks source link

Not able to deploy raffle.sol because of chainlink imports (overide problems)?! #111

Closed georgeziozas closed 1 year ago

georgeziozas commented 1 year ago

Greetings everyone,

I am at timestamp: 15:20:00 of the video where i try to deploy for the first time the Raffle.sol file. It seems for me that my code does not understand the imports of chainlink libraries correct.

The main problem seems to be that my functions are not overriding the correct base functions. I cannot really figure out why though.

Below i state my error:

PS C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp> yarn hardhat deploy
yarn run v1.22.19
warning package.json: No license field
$ "C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\.bin\hardhat" deploy
TypeError: Function has override specified but does not override anything.
  --> contracts/Raffle.sol:99:9:
   |
99 |         override
   |         ^^^^^^^^

TypeError: Function has override specified but does not override anything.
   --> contracts/Raffle.sol:116:16:
    |
116 |     ) external override {
    |                ^^^^^^^^

TypeError: Contract "Raffle" should be marked as abstract.
  --> contracts/Raffle.sol:24:1:
   |
24 | contract Raffle is VRFConsumerBaseV2, KeeperCompatibleInterface {
   | ^ (Relevant source part starts here and spans across multiple lines).
Note: Missing implementation: 
  --> @chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol:22:3:
   |
22 |   function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData);
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Missing implementation: 
  --> @chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol:40:3:
   |
40 |   function performUpkeep(bytes calldata performData) external;
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: Invalid type for argument in function call. Invalid implicit conversion from literal_string "" to bytes ca
requested.
   --> contracts/Raffle.sol:117:45:
    |
117 |         (bool upkeepNeeded, ) = checkUpKeep("");
    |                                             ^^

TypeError: Return argument type uint32 is not implicitly convertible to expected type (type of first return variable)s.
   --> contracts/Raffle.sol:176:16:
176 |         return NUM_WORDS;
    |                ^^^^^^^^^

TypeError: Type is not callable
   --> contracts/Raffle.sol:180:16:
    |
180 |         return s_players.length();
    |                ^^^^^^^^^^^^^^^^^^

Error HH600: Compilation failed

Here i state the code of the raffle.sol that i face the problem with:

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";

/* Errors */
error Raffle__NotEnoughETHEntered();
error Raffle__TransferFailed();
error Raffle__NotOpen();
error Raffle__UpkeepNotNeeded(uint256 currentBalance, uint256 numPlayers, uint256 raffleState);

/** @title A sample Raffle Contract
 * @author George Ziozas
 * @notice This contract is for creating an untamperable decentralized smart contract
 * @dev This implements Chainlink VRF v2 and ChainLinkKeepers
 */
contract Raffle is VRFConsumerBaseV2, KeeperCompatibleInterface {
    /*Type Declarations */
    enum RaffleState {
        OPEN,
        CALCULATING
    } //Essentially enum equals to: uint256 0=OPEN, uint256 1 = Calculating

    /*State Variables */
    uint64 private immutable i_subscriptionId;
    bytes32 private immutable i_gasLane;
    uint32 private immutable i_callbackGasLimit;
    uint16 private constant REQUEST_CONFIRMATIONS = 3;
    uint32 private constant NUM_WORDS = 1;
    VRFCoordinatorV2Interface private immutable i_vrfCoordinator;

    /*Lottery Variables*/
    address payable[] private s_players;
    uint256 private immutable i_entranceFee;
    address private s_recentWinner;
    RaffleState private s_raffleState;
    uint256 private s_lastTimeStamp;
    uint256 private immutable i_interval;

    /*Events*/
    event RaffleEnter(address indexed player);
    event RequestedRaffleWinner(uint256 indexed requestId);
    event WinnerPicked(address indexed winner);

    /*Functions*/
    constructor(
        address vrfCoordinatorV2,
        uint64 subscriptionId,
        bytes32 gasLane, // keyHash
        uint256 entranceFee,
        uint32 callbackGasLimit,
        uint256 interval
    ) VRFConsumerBaseV2(vrfCoordinatorV2) {
        i_entranceFee = entranceFee;
        i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
        i_gasLane = gasLane;
        i_interval = interval;
        i_subscriptionId = subscriptionId;
        i_callbackGasLimit = callbackGasLimit;
        s_raffleState = RaffleState.OPEN;
        s_lastTimeStamp = block.timestamp;
        i_interval = interval;
    }

    /**
     * @dev This is the function that the chainlink keeper nodes call when they look for the'upkeepNeeded' to return true
     * The following should be true in order to return true:
     *  1. Our time interval should have passed (the interval we have set so chainlink can automatically pick a winner for our lottery)
     *  2. The lottery should have at least 1 player and have some ETH
     *  3. Our subscription is funded with Link
     *  4. A lottery should be in "open" state
     *
     */
    function checkUpKeep(
        bytes memory /*checkData*/
    )
        public
        override
        returns (
            bool upkeepNeeded,
            bytes memory /*performData*/
        )
    {
        bool isOpen = (RaffleState.OPEN == s_raffleState);
        bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval); //block.timestamp -last block timestamp
        bool hasPlayers = (s_players.length > 0);
        bool hasBalance = address(this).balance > 0;
        upkeepNeeded = (isOpen && timePassed && hasPlayers && hasBalance);
        return (upkeepNeeded, "0x0");
    }

    //This function will automatically be called by the chainkeeper network
    function performUpKeep(
        bytes calldata /*performData*/
    ) external override {
        (bool upkeepNeeded, ) = checkUpKeep("");
        if (!upkeepNeeded) {
            revert Raffle__UpkeepNotNeeded(
                address(this).balance,
                s_players.length,
                uint256(s_raffleState)
            );
        }
        /*
        Goal: Request the random number AND do something with it.
        Thats a 2 transaction process.
        This function is going to request the lucky number AND in a second function the number will be returned.
        */
        s_raffleState = RaffleState.CALCULATING;
        uint256 requestId = i_vrfCoordinator.requestRandomWords(
            i_gasLane,
            i_subscriptionId,
            REQUEST_CONFIRMATIONS,
            i_callbackGasLimit,
            NUM_WORDS
        );
        emit RequestedRaffleWinner(requestId);
    }
PatrickAlphaC commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be

Thanks!