Skip to content

Instantly share code, notes, and snippets.

@Ashar2shahid
Last active July 1, 2022 08:24
Show Gist options
  • Save Ashar2shahid/ca14fec16f95f1bfb65bdc5e2a49f1c7 to your computer and use it in GitHub Desktop.
Save Ashar2shahid/ca14fec16f95f1bfb65bdc5e2a49f1c7 to your computer and use it in GitHub Desktop.
contract Quantumon is ERC721, RrpRequesterV0, Ownable {
using Strings for uint256;
uint256[9958] public ids; //Array to store the Quantomon Id - This is different from the tokenId
uint256 private index; // Track the next TokenId to be minted
string private _baseURIextended; // The Extended baseUrl for ERC721
mapping(uint256 => string) private _tokenURIs; //Mapping a custom URI to a tokenId
address public airnode; //The address of the QRNG airnode
bytes32 public endpointIdUint256; // The endpointId of the airnode to fetch a single random number
address public sponsorWallet; // The address of the sponsorWallet that will be making the fullfillment transaction
// Mapping that maps the requestId for a random number to the fullfillment status of that request
mapping(bytes32 => bool) public expectingRequestWithIdToBeFulfilled;
//Mapping that maps the requestId to the address that made the request
mapping(bytes32 => address) requestToSender;
constructor(address _airnodeRrp)
RrpRequesterV0(_airnodeRrp)
ERC721("QUANTUMON", "QUANTUMON")
{
}
function setRequestParameters(
address _airnode,
bytes32 _endpointIdUint256,
address _sponsorWallet
) external onlyOwner {
airnode = _airnode;
endpointIdUint256 = _endpointIdUint256;
sponsorWallet = _sponsorWallet;
emit SetRequestParameters(airnode, endpointIdUint256, sponsorWallet);
}
function setBaseURI(string memory baseURI) external onlyOwner {
_baseURIextended = baseURI;
emit SetBaseURI(_baseURIextended);
}
function _setTokenURI(uint256 tokenId, string memory _tokenURI)
internal
virtual
{
require(
_exists(tokenId),
"ERC721Metadata: URI set of nonexistent token"
);
_tokenURIs[tokenId] = _tokenURI;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseURIextended;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
// If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
return string(abi.encodePacked(base, tokenId.toString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment