Trying to make an ERC20, feeling confused

Hello everyone,

I just recently began programming and I decided to make my own ERC-20 token, with the hope of posting it on UniSwap. I did some research and decided to inherit from the OpenZep ERC20 standard due to its tried and true code. I want to program a token that burns 5% of its total supply on every transaction. Here is my code so far:

Some questions:
1.) Since I inherited the ERC20 from github, I don't have to explicitly define all of the major functions
(i.e. transfer, _transfer, approve, etc) in the contract, correct?
2.) I generated some homemade burn logic that I think makes sense, see fxns calculateBurnAmount and burn. How do I incorporate this so that the smart contract knows to execute these functions during transactions? I was thinking I post the transfer function from the ERC20 standard and then just call my two burn functions in body while passing it 'amount'?

Thank you for any and all help. I am a total novice and so excited to be doing this!!

You are correct on both cases.

  1. You don't have to redefine all the major functions in the contract.
  2. To have it burn on every transaction. You actually need to do it in the transfer function.
    However your burning logic should be improved.
    In calculateBurnAmount, you should check the balance of the sender, because you will be burning his tokens. Check if the sender has enough balance for the amount to be transfered and the amount to be burned.
    Then in your burn function, it's easier to just call the _burn function from openzeppelin
1 Like

Hello and thank you for the reply, I've made some updates:

1.) So, my original intention was to calculate 5% of every transaction, and then burn that amount from the total supply, not from that individual sender. With that said, does this still require an additional check for the balance of the sender? I did include one anyway like you suggested.

2.) I also added an additional requirement to protect the burn function from lowering the _totalSupply below the _minimumSupply; see my second "require" statement in the calculateBurnAmount fxn. Maybe this isn't necessary though?

3.) Like you suggested, I called the OpenZeppelin _burn function, and passed it burnAmount (much easier, haha!)

4.) You can see at the bottom that I included the openZep transfer function, but before the boolean return I called my two burn functions (one of which calls openZep's _burn). Is this how I would implement it?

Thank you so much for your advice and help!