SyntaxError: Free functions cannot have visibility. #1434
Answered
by
iangechuki
AwaisTahseencode
asked this question in
Q&A
-
//SPDX-License-Identifier:MIT
pragma solidity 0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
//Errors
error Raffle__NotEnoughEthEntered();
error successTransactionError();
contract Raffle is VRFConsumerBaseV2{
//state Variables
uint256 private immutable i_entranceFee;
address payable [] private funders;
// VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
uint64 private immutable i_subId;
bytes32 private immutable i_gasLane;//gaslane is same as keyHash
uint16 private constant REQUEST_CONFIRMATION=3;
uint32 private immutable i_callBackGasLimit;
uint32 private constant RANDOM_WORDS=1;
//Lottery variables
address private s_recentWinner;
//Events
event raffleEnter(address indexed player);
event raffleEnterWinner(uint256 indexed requestId);
event winnerPicked(address indexed winner);
//Constructor
constructor(address vrfCoordinateV2,
uint256 entranceFee,
bytes32 gasLane,
uint64 subid,
uint32 callBackGasLimit
)
VRFConsumerBaseV2(vrfCoordinateV2) {
i_entranceFee=entranceFee;
i_gasLane=gasLane;
i_vrfCoordinator=VRFCoordinatorV2Interface(vrfCoordinateV2);
i_subId=subid;
i_callBackGasLimit=callBackGasLimit;
}
function enterRaffle() public{
if(msg.value<i_entranceFee)
revert Raffle__NotEnoughEthEntered();
funders.push(payable(msg.sender));
emit raffleEnter(msg.sender);
}
}
//Request Random winners
function requestRandomWinners()external{
//i_vrfCoordinator will return a request id that who is requesting it so we can save it
uint256 requestId= i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subId,
REQUEST_CONFIRMATION,
i_callBackGasLimit,
RANDOM_WORDS
//keyHash,subcriptionId,requestConfirmation,callBackGasLimit,numWords
);
emit raffleEnterWinner(requestId);
}
function fulfillRandomWords(uint256 /*requestId*/,uint256[] memory randomWords) internal override {
uint256 indexOfWinner=randomWords[0]%funder.length;
address payable recentWinner=funder[indexOfWinner];
s_recentWinner=recentWinner;
(bool success,)=recentWinner.call{value:address(this).balance}("");
if(!success)
revert successTransactionError();
emit winnerPicked(recentWinner);
}
function getRecentWinner() public view returns(address){
return s_recentWinner;
}
I am facing compilation error , like free functions cannot have visibility , undeclared identifier , for further clarity images are attached , kindly help me to figure out the error |
Beta Was this translation helpful? Give feedback.
Answered by
iangechuki
Jul 31, 2022
Replies: 2 comments
-
You have declared the following functions outside the contract |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AwaisTahseencode
-
Make a repo, so I can publish changes directly. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have declared the following functions outside the contract
requestRandomWinners
,fulfillRandomWords
,getRecentWinner
.Move them back into the contract and the errors should go away.