-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Hi Guys,
while doing the assignment i ran into the following error:
Undeclared identifier. "requestRandomnessForNFTUris" is not (or not yet) visible at this point.
I cant seem to find out what im doing wrong.
Here is my code:
`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
//OpenZeppelin Imports
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
// Chainlink Imports
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol";
contract BullAndBear is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable, KeeperCompatibleInterface, VRFConsumerBaseV2 {
using Counters for Counters.Counter;
using Strings for uint32;
Counters.Counter private _tokenIdCounter;
uint public intervalSeconds;
uint public lastTimeStamp;
uint64 s_subscriptionId;
uint256[] public requestIds;
uint256 public lastRequestId;
int256 public currentPrice;
uint256[] s_randomWords;
//parameters for VRF ChainLink
uint32 public callbackGasLimit = 100000;
bytes32 keyHash = 0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15;
uint16 requestConfirmations = 3;
uint32 numWords = 2;
struct RequestStatus {
bool fulfilled; // whether the request has been successfully fulfilled
bool exists; // whether a requestId exists
uint256[] randomWords;
}
mapping(uint256 => RequestStatus) public s_requests;
enum MarketTrend {
Bear,
Bull
}
MarketTrend currentMarketTrend = MarketTrend.Bull;
AggregatorV3Interface public pricefeed;
VRFCoordinatorV2Interface public COORDINATOR;
string[] bullUrisIpfs = [
"https://ipfs.io/ipfs/QmRXyfi3oNZCubDxiVFre3kLZ8XeGt6pQsnAQRZ7akhSNs?filename=gamer_bull.json",
"https://ipfs.io/ipfs/QmRJVFeMrtYS2CUVUM2cHJpBV5aX2xurpnsfZxLTTQbiD3?filename=party_bull.json",
"https://ipfs.io/ipfs/QmdcURmN1kEEtKgnbkVJJ8hrmsSWHpZvLkRgsKKoiWvW9g?filename=simple_bull.json"
];
string[] bearUrisIpfs = [
"https://ipfs.io/ipfs/Qmdx9Hx7FCDZGExyjLR6vYcnutUR8KhBZBnZfAPHiUommN?filename=beanie_bear.json",
"https://ipfs.io/ipfs/QmTVLyTSuiKGUEmb88BgXG3qNC8YgpHZiFbjHrXKH3QHEu?filename=coolio_bear.json",
"https://ipfs.io/ipfs/QmbKhBXVWmwrYsTPFYfroR2N7NAekAMxHUVg2CWks7i9qj?filename=simple_bear.json"
];
event TokensUpdated(string marketTrend);
event RequestSent(uint256 requestId, uint32 numWords);
event RequestFulfilled(uint256 requestId, uint256[] randomWords);
constructor(uint _intervalSeconds, address _pricefeed, uint64 subscriptionId)
ERC721("BullAndBear", "BBNFT")
VRFConsumerBaseV2(0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D) {
//Sets keeper update interval.
intervalSeconds = _intervalSeconds;
lastTimeStamp = block.timestamp;
//set subcriptionId for VRF
s_subscriptionId = subscriptionId;
//set to a pricefeed on goerli network. currently set to BTC/USD goerli
pricefeed = AggregatorV3Interface(_pricefeed);
//currently hardcoded for goerli interface
COORDINATOR = VRFCoordinatorV2Interface(0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D);
// set the price for the chosen currency pair.
currentPrice = getLatestPrice();
}
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
//Defaults to gammer bull NFT image
string memory defaultUri = bullUrisIpfs[0];
_setTokenURI(tokenId, defaultUri);
}
function checkUpkeep(bytes calldata /*checkData*/)external view override returns(bool upkeepNeeded, bytes memory /*performData*/){
upkeepNeeded = (block.timestamp - lastTimeStamp) > intervalSeconds;
}
function performUpkeep(bytes calldata /*performData*/) external override{
require((block.timestamp - lastTimeStamp) > intervalSeconds);
lastTimeStamp = block.timestamp;
int latestPrice = getLatestPrice();
if(latestPrice == currentPrice){
return;
}
if (latestPrice < currentPrice){
currentMarketTrend = MarketTrend.Bear;
} else{
currentMarketTrend = MarketTrend.Bull;
}
requestRandomnessForNFTUris();
currentPrice = latestPrice;
}
function requestRandomnessForNFTUris()
external
onlyOwner
returns (uint256 requestId)
{
// Will revert if subscription is not set and funded.
requestId = COORDINATOR.requestRandomWords(
keyHash,
s_subscriptionId,
requestConfirmations,
callbackGasLimit,
numWords
);
s_requests[requestId] = RequestStatus({
randomWords: new uint256[](0),
exists: true,
fulfilled: false
});
requestIds.push(requestId);
lastRequestId = requestId;
emit RequestSent(requestId, numWords);
return requestId;
}
function fulfillRandomWords(
uint256 _requestId,
uint256[] memory _randomWords
) internal override {
require(s_requests[_requestId].exists, "request not found");
s_requests[_requestId].fulfilled = true;
s_requests[_requestId].randomWords = _randomWords;
emit RequestFulfilled(_requestId, _randomWords);
string[] memory urisForTrend = currentMarketTrend == MarketTrend.Bull ? bullUrisIpfs : bearUrisIpfs;
uint256 idx = s_randomWords[0] % urisForTrend.length;
for (uint i = 0; i < _tokenIdCounter.current() ; i++) {
_setTokenURI(i, urisForTrend[idx]);
}
string memory trend = currentMarketTrend == MarketTrend.Bull ? "bull market" : "bear market";
emit TokensUpdated(trend);
}
function getRequestStatus(
uint256 _requestId
) external view returns (bool fulfilled, uint256[] memory randomWords) {
require(s_requests[_requestId].exists, "request not found");
RequestStatus memory request = s_requests[_requestId];
return (request.fulfilled, request.randomWords);
}
function getLatestPrice() public view returns(int256){
(,int price,,,) = pricefeed.latestRoundData();
return price;
}
function updateInterval(uint256 newInterval) public onlyOwner{
intervalSeconds = newInterval;
}
function updatePricefeed(address newFeed) public onlyOwner{
pricefeed = AggregatorV3Interface(newFeed);
}
function updateSubscriptionId(uint64 newId) public onlyOwner {
s_subscriptionId = newId;
}
//helperfunctions
/**
@dev check if strings are equal
*/
function checkEqualStrings(string memory a, string memory b) internal pure returns(bool){
return (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)));
}
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId, batchSize);
}
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
`