Skip to main content

Platform Fee

PlatformFee allows you to charge a percentage fee wherever there is a transfer of currency in your contract.

Unlocked Features

Once deployed, you can use the features made available by these contracts on the SDK and dashboard:

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;
}
}