-
Notifications
You must be signed in to change notification settings - Fork 575
Update Solidity version and refactor ContractMetadata #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
pragma solidity ^0.8.19; | ||
|
||
/// @author thirdweb | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
import "./interface/IContractMetadata.sol"; | ||
contract RebelByNature is ERC721URIStorage, Ownable, ContractMetadata { | ||
uint256 public nextTokenId; | ||
|
||
/** | ||
* @title Contract Metadata | ||
* @notice Thirdweb's `ContractMetadata` is a contract extension for any base contracts. It lets you set a metadata URI | ||
* for you contract. | ||
* Additionally, `ContractMetadata` is necessary for NFT contracts that want royalties to get distributed on OpenSea. | ||
*/ | ||
event TributeMinted(uint256 tokenId, address recipient, uint256 timestamp); | ||
|
||
abstract contract ContractMetadata is IContractMetadata { | ||
/// @dev The sender is not authorized to perform the action | ||
error ContractMetadataUnauthorized(); | ||
constructor() ERC721("Rebel By Nature", "SEQREB") {} | ||
|
||
/// @notice Returns the contract metadata URI. | ||
string public override contractURI; | ||
|
||
/** | ||
* @notice Lets a contract admin set the URI for contract-level metadata. | ||
* @dev Caller should be authorized to setup contractURI, e.g. contract admin. | ||
* See {_canSetContractURI}. | ||
* Emits {ContractURIUpdated Event}. | ||
* | ||
* @param _uri keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") | ||
*/ | ||
function setContractURI(string memory _uri) external override { | ||
if (!_canSetContractURI()) { | ||
revert ContractMetadataUnauthorized(); | ||
} | ||
|
||
_setupContractURI(_uri); | ||
function mintTribute(address recipient) external onlyOwner { | ||
uint256 tokenId = nextTokenId++; | ||
_mint(recipient, tokenId); | ||
_setTokenURI(tokenId, contractURI); | ||
emit TributeMinted(tokenId, recipient, block.timestamp); | ||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix compile error and mint safety: call contractURI(), use _safeMint
Apply: - function mintTribute(address recipient) external onlyOwner {
- uint256 tokenId = nextTokenId++;
- _mint(recipient, tokenId);
- _setTokenURI(tokenId, contractURI);
- emit TributeMinted(tokenId, recipient, block.timestamp);
- }
+ function mintTribute(address recipient) external onlyOwner {
+ uint256 tokenId = nextTokenId++;
+ _safeMint(recipient, tokenId);
+ _setTokenURI(tokenId, contractURI());
+ emit TributeMinted(tokenId, recipient, block.timestamp);
+ } Optional: accept a per‑token URI to avoid copying the contract‑level URI into token metadata. function mintTribute(address recipient, string calldata uri) external onlyOwner {
uint256 tokenId = nextTokenId++;
_safeMint(recipient, tokenId);
_setTokenURI(tokenId, uri);
emit TributeMinted(tokenId, recipient, block.timestamp);
} 🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
/// @dev Lets a contract admin set the URI for contract-level metadata. | ||
function _setupContractURI(string memory _uri) internal { | ||
string memory prevURI = contractURI; | ||
contractURI = _uri; | ||
|
||
emit ContractURIUpdated(prevURI, _uri); | ||
function _canSetContractURI() internal view override returns (bool) { | ||
return msg.sender == owner(); | ||
} | ||
|
||
/// @dev Returns whether contract metadata can be set in the given execution context. | ||
function _canSetContractURI() internal view virtual returns (bool); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContractMetadata
is undefined—missing import/definition.The contract inherits
ContractMetadata
, but that type is no longer declared in this file nor imported from elsewhere, so the compiler cannot resolve it. Reintroduce the original extension declaration here or import the correct contract before using it.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./ContractMetadata.sol";
contract RebelByNature is ERC721URIStorage, Ownable, ContractMetadata {
uint256 public nextTokenId;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 4558
🏁 Script executed:
Length of output: 930
@sonnyquinn24, the import
import "./ContractMetadata.sol";
creates a self-import (the file importing itself), which will cause a circular dependency compilation error.The Problem
You've completely replaced the
ContractMetadata.sol
file, which originally contained an abstract contract extension, with yourRebelByNature
contract. The file cannot import itself.Recommended Solution: Separate Files
Restore
contracts/extension/ContractMetadata.sol
to its original content and create a new file for your contract:contracts/extension/ContractMetadata.sol (restore original):
contracts/RebelByNature.sol (new file):
Note: I also added
Ownable(msg.sender)
to the constructor, which is required for OpenZeppelin's Ownable in v5.x if you're using that version.Alternative: Combined File (Not Recommended)
If you prefer a single file, include both contract definitions:
The separate files approach is strongly recommended to maintain the repository's extension architecture.