Skip to main content

Contract Royalties

Using the Contract Royalties features on your contract allows you to control the royalty settings for your contract, which are used to calculate royalties on any secondary sales of assets.

You can add this interface to your contract by implementing all of the functions in the IRoyalty interface as shown below:

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

import "@thirdweb-dev/contracts/ThirdwebContract.sol";
import "@thirdweb-dev/contracts/feature/interface/IRoyalty.sol";

// We add the interface to the contract
contract MyCustomContract is ThirdwebContract, IRoyalty {

// Implement the permissions functions below

}

Alternatively, you can use our Royalty implementation of the IRoyalty interface to get royalty functionality for your contract out-of-the-box as follows:

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

import "@thirdweb-dev/contracts/ThirdwebContract.sol";
import "@thirdweb-dev/contracts/feature/interface/Royalty.sol";

// We add the interface to the contract
contract MyCustomContract is ThirdwebContract, Royalty {

// Now this contract will have royalties out of the box

}

If your contract implements all the functions in this standard, you will get support for the following SDK interface.

const contract = await sdk.getContract("{{contract_address}}");
const royaltyInfo = await contract.royalties.getDefaultRoyaltyInfo();
await contract.roles.setTokenRoyaltyInfo(tokenId, {
seller_fee_basis_points: 100, // 1% royalty fee
fee_recipient: "0x...", // the fee recipient
});
View in Javascript SDK Documentation