I am using npm openzepplin wizard library for making erc20 token that can be mintable,pausable and burnable.
Is there any library or method exist that help me to add Royalty to an erc20 token
What do you mean with
You need to create a separate contract for the royalty payments and have the token contract call the royalty contract to transfer a percentage of the tokens to the owner of the asset whenever the tokens are transferred. You could use the SafeERC20
contract from the OpenZeppelin library to add a royalty payment whenever the transfer
function is called on your ERC20 token contract. The SafeERC20
contract provides a number of safety checks and utilities that can be used to ensure the integrity of your ERC20 token contract.
Example of how you might use the SafeERC20
contract to add a royalty payment:
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
contract MyToken is SafeERC20 {
// Your token contract code goes here...
function transfer(address _to, uint256 _value) public virtual override {
// Transfer the tokens
super._transfer(_to, _value);
// Call the royalty contract to transfer a percentage of the tokens to the owner of the asset
royaltyContract.transfer(_value * royaltyPercentage / 100, owner);
}
}
There are no features out of the box in OpenZeppelin Contracts that implement royalties for ERC20 tokens.