Skip to main content

Platform Fee

The PlatformFee smart contract extension is usable with any base smart contract. “Platform fee” is a generic fee that you can choose to charge in your smart contract, wherever there is a transfer of currency. The PlatformFee extension lets you set a recipient and a % for this generic fee.

Import

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

Available functionality

FunctionalityDescription
getPlatformFeeInfoReturns the platform fee recipient and % of a currency transfer to take as platform fee.
setPlatformFeeInfoLets an authorized wallet set platform fee percentage and recipient.
_canSetPlatformFeeInfoDefines the criteria a wallet must meet to be able to set any platform fee percentage and recipient.

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/PlatformFee.sol";

contract MyContract is PlatformFee {
/**
* 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 `PlatformFee` extension.
*/
address public deployer;

constructor() {
deployer = msg.sender;
}

/**
* This function returns who is authorized to set platform fee info for your contract.
*
* As an EXAMPLE, we'll only allow the contract deployer to set the platform fee info.
*
* You MUST complete the body of this function to use the `PlatformFee` extension.
*/
function _canSetPlatformFeeInfo() 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 platform fee under the Settings tab:

Batch Upload

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