Thank you for reading this post.

I can make a basic ERC20 token, but I am really struggling to find anything that explains how to add fees.

My intention is to create a token with 3 fees. One fee will be distributed to the holders, one will be used for liquidity and the other will go to the dev wallet for promotions and giveaways.

I have read through the uniswap docs but can not find how to implement this into my code. I am using remix. I have imported what I believe are all the required files, as well as the standard ERC20 files from git hub.

Using the following code as a base to build on, what do I need to do next?

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";

contract TestToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Test_Token", "TT") {
        _mint(msg.sender, initialSupply);

import '@uniswap/v2-core/contracts/interfaces/IUniswapV2ERC20.sol';
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol';
import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol';
import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';

This is a problem I've been trying to solve for 2 weeks. I initial tried to copy existing contracts that take fees and have automated liquidity, then deploy those, but none of them would deploy on remix, most of them would not even compile. I tried this on the javascript VM and using Ganache on the Goerli network.

I cannot find anything that helps with this problem and have spent days reading through various documentation on many sites. Can anybody point me in the direction of something that specifically addresses adding fees in this way.

While trying to use code copied from existing files I set all tax fees to 0 and set swapandliquify to false before trying to deploy, but I was still unable to deploy. However, I would rather not just copy another contract. I'd like to know how to do this myself.

Aside of 'How do I do it?' the following are areas that I am unsure about.

  1. Is it possible to do what I want to do only using remix? Or do I need to use something like truffle and compile using the command line. I would much prefer to do everything in remix.

  2. Do the files I am importing from uniswap only cover adding liquidity, or are these also used for fee distribution and fee collection?

  3. Do I need to deploy some contracts before others? I've seen some information about getting an address after deploying and then putting this back into the code to deploy the main contract. Can anybody explain how this works? Is there an order to deploy, I assumed I can simply deploy the TestToken - test.sol as this works fine for a 'vanilla' token, but do I need to get the token address and add this somewhere for the swapandliquify function to work?

Every day I spend hours trying to solve these problems and I am making no progress at all. Any help whatsoever would be very much appreciated. Even just pointing me to documentation for one aspect of this so I can finally start moving forward again would be a really great help.

Obviously, taking fees for these 3 purposes is possible as it is something that many contracts are already doing. I know I'm missing something here. It feels a bit like I can't see the wood for the trees, like I'm missing something glaringly obvious while focussing on tiny snippets of code.

I am relatively new to solidity, I am currently working through a paid solidity development course via Udemy as well as many free trainings, I'm about 2/3 through the course, but I've skipped ahead to see if any future lectures address this but they do not.

Thanks for taking the time to read this, I hope you can help me to move forward. My project was moving along very well, and now this is holding everything up.

  • Start creating the token with fees, nothing else. – Ismael May 9 at 21:13
  • Can you please elaborate on that a little more? Even if I just want one fee that goes to a wallet, what should I do to get it to deploy via remix? Thanks. – GenTokens.com May 10 at 20:53
  • I'd suggest to start learning about solidity and remix. – Ismael May 11 at 1:22
  • I am. I have almost completed this course: udemy.com/course/blockchain-developer and I'm studying as many docs as I can find. Whenever I add a fee, the deployment fails, with various errors. I then spend about 3 or 4 hours looking through everything I can find about the errors I get and none of it has helped. So I asked here in case somebody might be able to suggest a solution that works. – GenTokens.com May 11 at 4:34
  • If you want to point me at something you think will help, please do – GenTokens.com May 11 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.