How does this line "VRFCoordinatorV2Interface(vrfCoordinator)" work? #466
-
I understand that we are matching an ABI/Interface with a contract address, but how exactly does /*this lets us inherit all functionality from VRFConsumerBaseV2. When a contract inherits from other contracts, only a single contract is created on the blockchain,
and the code from all the base contracts is compiled into the created contract.
This means that all internal calls to functions of base contracts also just use internal function call*/
contract Raffle is VRFConsumerBaseV2 {
/*State Variables*/
address payable[] private s_players; //s stands for storage. This variable has to be in storage because we are modifying it a lot
uint256 private immutable i_entranceFee; //this is immutable so we can save some gas. i stands for immutable
VRFCoordinatorV2Interface private immutable i_vrfCoordinator; //here we match an ABI/VRFCoordinatorV2Interface with a var so that we can use VRFCoordinatorV2Interface as our only reference to that contract
/*Events*/
event RaffleEnter(address indexed player);
constructor(address vrfCoordinatorV2, uint256 entranceFee) VRFConsumerBaseV2(vrfCoordinatorV2) {
i_entranceFee = entranceFee;
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2); //here we match and abi with an address so we can interact with the contract. Wrap interface around the address
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I love the annotations :) So, you can call functions on a contract when you have two things:
That line basically "wraps" that address in the ABI, allowing us to call any function in the contract at that address. So we are saying: At address Does that make sense? |
Beta Was this translation helpful? Give feedback.
I love the annotations :)
So, you can call functions on a contract when you have two things:
That line basically "wraps" that address in the ABI, allowing us to call any function in the contract at that address. So we are saying:
At address
vrfCoordinatorV2
, we assume it has functions from the ABIVRFCoordinatorV2Interface
.Does that make sense?