OpenZeppelin / OpenZeppelin/contracts-wizard
Add Royalties for NFTs
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 294
- Forks
- 186
- Avg merge
- 6h 46m
- Merged PRs (30d)
- 22
Description
Add options for users to be able to integrate royalties on their ERC721 and ERC1155 contracts. This is a suggested set of changes:
-
Include it on the options after selecting ERC721 or ERC1155.

Populating those fields would inherit from the tokenRoyalty contract and call the setDefaultRoyalty from the constructor. -
Include this parts on the code:
- An import for the new module:
import "@openzeppelin/contracts/token/tokenERC/extensions/tokenERCRoyalty.sol"; - An inheritance:
contract MyToken is ERC721, AccessControl {We'll use Access control to handle the roles of who can set royalties. - This calls to the royalties functions:
- An import for the new module:
function setTokenRoyalty(
uint256 tokenId,
address recipient,
uint96 fraction
) public onlyRole(ROYALTY_SETTER_ROLE) {
_setTokenRoyalty(tokenId, recipient, fraction);
}
function setDefaultRoyalty(address recipient, uint96 fraction) public onlyRole(ROYALTY_SETTER_ROLE) {
_setDefaultRoyalty(recipient, fraction);
}
- [ ] This constructor:
bytes32 public constant ROYALTY_SETTER_ROLE= keccak256("ROYALTY_SETTER_ROLE");
constructor() ERC721("MyToken", "MTK") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ROYALTY_SETTER_ROLE, msg.sender);
}
Take into consideration for the ERC1155, if the user specifies royalties and select ERC1155Supply do not import it btwice into the code, since the royalties contract inherits from this module.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how ERC721 and ERC1155 options are presented and how their contract code is generated. Add royalty configuration and generated access-controlled royalty methods for both standards, ensuring ERC1155Supply does not receive a duplicate import; done means the selected options produce valid contracts with the requested constructor behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity, typescript
- Domain
- blockchain, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100