PlatformFee

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

PlatformFee allows you to charge a percentage fee wherever there is a transfer of currency (ERC20 tokens or native tokens) in your contract.

GitHub
View on GitHub

Usage

The PlatformFee extension is an abstract contract, and expects you to implement the following functions by yourself:

NameTypeReturnsDescription
_canSetPlatformFeeInfointernal view virtualboolRuns on every attempt to set a new platform fee recipient or bps. Returns whether this info can be set in the given execution context.

This is an example smart contract demonstrating how to inherit from this extension and override the functions to add (optional) custom functionality.

// 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 view virtual override returns (bool) {
return msg.sender == deployer;
}
}

Base Contracts Implementing This Extension

None of the base contracts implement this extension.

Full API reference