Skip to main content

Royalties

The Royalty smart contract is an extension usable with any base smart contract. It implements EIP 2981 NFT royalty standard for royalty support on NFT marketplaces.

Import

import "@thirdweb-dev/contracts/extension/Royalty.sol";

Available functionality

FunctionalityDescription
royaltyInfoReturns the recipient of royalties and the % of sales to take as royalties, for a given NFT.
getDefaultRoyaltyInfoReturns the default recipient of royalties and the default % of sales to take as royalties, for any given NFT.
setDefaultRoyaltyInfoLets you set the default royalty recipient and % for your NFTs.
getRoyaltyInfoForTokenReturns the recipient of royalties and the % of sales to take as royalties, for an NFT of a particular token ID.
setRoyaltyInfoForTokenLets you set the royalty recipient and % for an NFT of a particular tokenID.
_canSetRoyaltyInfoDefines the criteria a wallet must meet to be able to set any royalty percentage and recipient.

The Royalty contract extension lets you set a default recipient address for royalties generated by the secondary sales of your NFTs, and a default percentage of secondary sales to take as royalties.

You can also override the royalty recipient and percentage for your NFTs on a per token ID basis.

Implementing the Contract extension

Import the contract extension and make your contract inherit it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/extension/Royalty.sol";

contract MyContract is Royalty {

/**
* We store the contract deployer's address only for the purposes of the example
* in the code comment below.
*
* Doing this is not necessary to use the `Royalty` extension.
*/
address public deployer;

constructor() {
deployer = msg.sender;
}

/**
* This function returns who is authorized to set royalty info for your NFT contract.
*
* As an EXAMPLE, we'll only allow the contract deployer to set the royalty info.
*
* You MUST complete the body of this function to use the `Royalty` extension.
*/
function _canSetRoyaltyInfo() internal virtual override returns (bool){
return msg.sender == deployer;
}
}

Unlocked Features

On the dashboard, you'll be able to set the wallet address and percentage of the royalty fee on secondary sales under the Settings tab:

Batch Upload

Within the SDK, you can get and set the royalty fee (if you have the necessary permissions).