I have a rather interesting but challenging question. I want to create ERC-1155 and ERC-721 tokens that will be primarily traded using a Decentralized Exchange (DEX) implemented for a newly created protocol. However, I want to allow those tokens to be traded on external DEXes such as OpenSea. That is possible, no question about, but my question relates to protocol fees earned on transactions.

Is there a way of accruing protocol fees on transactions (trades) even if they are not on the native DEX? It would seem to me it should be possible by programming the smart contract such the protocol fee is always collected, but I am not clear on how that would work practically.

Any ideas? Is there something obvious that I am not thinking about?

Possible solution

Could I implement the solution suggested by @porton as follows? This is now slightly updated to include a percentage.

contract myNFT {
    address public immutable feeAddress;
    uint256 public immutable feePercentage;

    // Set address to receive fees
    constructor (address feeAddress, feePercentage) public {
        feeAddress = _feeAddress;
        feePercentage = _feePercentage;

    // Some other stuff

    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable {

        uint256 private _feeAmount;
        _feeAmount = (getLastTradePrice()*feePercentage/10^18);

// This only works if sufficient funds have been provided for the fees. Otherwise the trade will fail

        // Some other stuff

getLastTradePrice() will access an Oracle managed by the protocol to track trades made on external trading platforms.

Could this work?

  • Can you clarify a few things ... "for a newly created protocol": do you mean a protocol on Ethereum or some other chain? "I want to allow those tokens to be traded on external DEXes such as OpenSea": what do you mean by "external"? OpenSea has contracts running on Ethereum afaik.
    – Sasa Milic
    Commented Mar 1, 2021 at 23:23
  • Assuming these are all protocols on Ethereum, "Is there a way of accruing protocol fees on transactions (trades) even if they are not on the native DEX?" You can track trades of any ERC-721 (for example) by checking for Transfer events.
    – Sasa Milic
    Commented Mar 1, 2021 at 23:29
  • Re: "protocol fee". Do you mean the trading fee charged by some "external DEXes" (i.e. external to the system you're building)?
    – Sasa Milic
    Commented Mar 1, 2021 at 23:29
  • @Sasa Milic - the protocol would be created on Ethereum. There would be a DEX as part of the protocol and used by the front-end. What is Ethereum AFAIK? Commented Mar 2, 2021 at 5:40
  • @Sasa Milic - The problem with checking Transfer events is that it is after the fact. How do you know in real-time and charge a small fee for external trades? Commented Mar 2, 2021 at 5:42

1 Answer 1


It is easy to create an NFT that transfers a fixed fee to you at every transfer of this NFT. Just add transfer (of ETH, or an ERC-20/1155) to it.

It is nearly impossible to get a transaction percentage every time a token is traded:

  • Suppose somebody buys your token on Uniswap. Then your token receives from a Uniswap a message to be transferred. The token can know that it is Uniswap (if somebody does not use an unknown to your token clone of Uniswap or something other), but can't know the details of the Uniswap transaction (such a the buying token amount) because it is not yet mined, so your contract does not know the amount.
  • You can know prices of tokens from Uniswap or Chainlink, for instance, but not every token is listed there. So you don't know the price.
  • Somebody may create a new token specifically to buy your token and manipulate its price to be zero. So your percentage would be zero.
  • Thanks for this. This is really helpful. I have made an attempt to create a code example of how this would look like. Please take a look at my updated question which includes some code snippet. Would that approach work? I suppose it would be possible to also adjust the amount of the transaction fee based on some reference index. What do you think? Commented Mar 5, 2021 at 9:11
  • One other thought, even if I don't know the current trading price, don't I always know the last traded price? Whether OpenSea or Raribles or whatever, the last traded price should always be known won't it? If so, in which smart contract variable is it stored? Thanks again! Commented Mar 5, 2021 at 9:40
  • The trading price may stored (or not stored) in something like a Uniswap contract. Concerning OpenSea or Raribles I don't know.
    – porton
    Commented Mar 6, 2021 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.